Page 89 - CTS - CSA TP - Volume 2
P. 89
COMPUTER SOFTWARE APPLICATION - CITS
After all the iteration and comparisons of elements, we get a sorted array.
TASK 4: Sort array in descending order
// Sort array in descending order
import java.util.Scanner;
public class BubbleSortDescending {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Prompt the user to enter the number of elements
System.out.print(“Enter the number of elements: “);
int n = scanner.nextInt();
// Create an array of the specified size
int[] arr = new int[n];
// Prompt the user to enter array elements
System.out.println(“Enter the elements of the array:”);
for (int i = 0; i < n; i++) {
74
CITS : IT & ITES - Computer Software Application - Exercise 93