Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
4b
//'main' method must be in a class 'Rextester'. //openjdk version '11.0.5' //Lokeshreddy 7002 import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { int count, temp; Scanner scan = new Scanner(System.in); System.out.print("\nNumber of elements in an array: "); count = scan.nextInt(); int num[] = new int[count]; System.out.println("\nElements in an array:"); for (int i = 0; i < count; i++) { num[i] = scan.nextInt(); } for (int i = 0; i < count; i++) { for (int j = i + 1; j < count; j++) { if (num[i] > num[j]) { temp = num[i]; num[i] = num[j]; num[j] = temp; } } } System.out.print("\nElements in Ascending Order: "); for (int i = 0; i < count - 1; i++) { System.out.print(num[i] + ", "); } System.out.print(num[count - 1]); } }
run
|
edit
|
history
|
help
0
Write a program to sort the odd elements descending order and even elements in ascending order
h
A.K.JAVA_EXPERIENCE_1
project euler 12, java
Street light
evenloop
postincrement2
2A
ClientesJava v2
jb14.0 lyambds