Opening Hours :7AM to 9PM
import java.util.Arrays; import java.util.Comparator; public class Main { public static void main(String[] args) { Integer[] arr = {3, 6, 1, 2, 5, 4}; Arrays.sort(arr, Comparator.reverseOrder()); for (int i : arr) { System.out.print(i + " "); } } }In this example, the program creates an array arr of integers and assigns it the values {3, 6, 1, 2, 5, 4}. The Arrays.sort(arr, Comparator.reverseOrder()) line sorts the array in descending order using the Comparator.reverseOrder().
import java.util.Arrays; import java.util.Comparator; public class Main { public static void main(String[] args) { Integer[] arr = {3, 6, 1, 2, 5, 4}; Arrays.sort(arr, (x, y) -> y - x); for (int i : arr) { System.out.print(i + " "); } } }Additionally, you can implement your own sorting algorithm and reverse the order of swapping the elements of the array. This will sort the array in descending order.