15. Program to sort the elements of an array in descending order
💡Code:
import java.util.Arrays; import java.util.Collections; public class SortArrayDescending7078 { public static void main(String[] args) { // Example array Integer[] numbers = {15, 7, 23, 45, 9, 56, 82, 31}; // Integer type for sorting in descending order // Sort the elements of the array in descending order sortArrayDescending7078(numbers); // Print the sorted array System.out.println("Sorted array in descending order: " + Arrays.toString(numbers)); } // Function to sort the elements of an array in descending order private static void sortArrayDescending7078(Integer[] array) { Arrays.sort(array, Collections.reverseOrder()); } }
📸Output :
.png)