1Integer[] cubes = new Integer[] { 8, 27, 64, 125, 256 };
2Arrays.sort(cubes, Collections.reverseOrder());
3
4Read more: https://www.java67.com/2016/07/how-to-sort-array-in-descending-order-in-java.html#ixzz6MX60xZLb
1int countOfArray = 5;
2int num [] = new int[counfOfArray];
3
4int num[] = [8 , 5 , 9 , 3 , 4];
5
6for (int i = 0; i < countOfArray; i++)
7 {
8 for (int j = i + 1; j < countOfArray; j++) {
9 if (num[i] > num[j])
10 {
11 temp = num[i];
12 num[i] = num[j];
13 num[j] = temp;
14 }
15 }
16 }
1import java.util.Scanner;
2public class JavaExample
3{
4 public static void main(String[] args)
5 {
6 int count, temp;
7
8 //User inputs the array size
9 Scanner scan = new Scanner(System.in);
10 System.out.print("Enter number of elements you want in the array: ");
11 count = scan.nextInt();
12
13 int num[] = new int[count];
14 System.out.println("Enter array elements:");
15 for (int i = 0; i < count; i++)
16 {
17 num[i] = scan.nextInt();
18 }
19 scan.close();
20 for (int i = 0; i < count; i++)
21 {
22 for (int j = i + 1; j < count; j++) {
23 if (num[i] > num[j])
24 {
25 temp = num[i];
26 num[i] = num[j];
27 num[j] = temp;
28 }
29 }
30 }
31 System.out.print("Array Elements in Ascending Order: ");
32 for (int i = 0; i < count - 1; i++)
33 {
34 System.out.print(num[i] + ", ");
35 }
36 System.out.print(num[count - 1]);
37 }
38}
1// A sample Java program to sort a subarray
2// in descending order using Arrays.sort().
3import java.util.Arrays;
4import java.util.Collections;
5
6public class SortExample
7{
8 public static void main(String[] args)
9 {
10 // Note that we have Integer here instead of
11 // int[] as Collections.reverseOrder doesn't
12 // work for primitive types.
13 Integer[] arr = {13, 7, 6, 45, 21, 9, 2, 100};
14
15 // Sorts arr[] in descending order
16 Arrays.sort(arr, Collections.reverseOrder());
17
18 System.out.printf("Modified arr[] : %s",
19 Arrays.toString(arr));
20 }
21}