Java Topics

1.Sort elements in descending order

public class Main {

public static void main(String[] args) {

int[] ar = { 20, 60, 10, 46 };

for (int i = 0; i < ar.length; i++) {

for (int j = i + 1; j < ar.length; j++) {

if (ar[i] < ar[j]) {

int temp = ar[i];

ar[i] = ar[j];

ar[j] = temp;

}

}

}

for (int k = 0; k < ar.length; k++) {

System.out.println(ar[k]);



}

}

}

Output:

60
46
20
10