This Java program sorts an array of integers in descending order. It takes user input for the array size and elements. Then it uses a double for loop to compare all elements and swap any that are out of order, putting the array in descending order. Finally it prints the sorted array.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
14 views1 page
Descending Order
This Java program sorts an array of integers in descending order. It takes user input for the array size and elements. Then it uses a double for loop to compare all elements and swap any that are out of order, putting the array in descending order. Finally it prints the sorted array.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1
/* Program to sort array elements in a descending order */
package com.automation; import java.util.Scanner;
public class SortDescendingOrder {
@SuppressWarnings("resource") public static void main(String[] args) { System.out.println("Enter the size of an array:"); Scanner size =new Scanner(System.in); int temp=0; int arr[] = new int[size.nextInt()]; /* Accept the array elements from the user */ System.out.println("Enter the elements of an array:"); Scanner sc1 =new Scanner(System.in); for(int i=0; i<arr.length; i++) { arr[i]= sc1.nextInt(); }