JAVA Program to Sort Array in Descending Order

JAVA Program to Sort Array in Descending Order:


class NumerSorting
{
 public static void main(String args[])
 {
  int number[] = {55,40,80,65,71};
  int n = number.length;
  System.out.print("Given list : ");
  for(int i =0; i< n; i++)
  {
   System.out.print(" "+number[i]);
  }
  System.out.print("\n");

   for(int i =0; i< n; i++)
    {
     for(int j =i+1; j< n; j++)
     {

     if (number[i] < number[j])
      {
       int temp = number[i];
       number[i] = number[j];
       number[j] = temp;
      }
     }
    }

    System.out.print("Sorted List : ");
    for(int i =0; i< n; i++)
    {
     System.out.print(" "+number[i]);
    }
    System.out.println(" ");
 }
}

OUTPUT:

Given list :  55 40 80 65 71
Sorted List :  80 71 65 55 40

Leave a Reply

Your email address will not be published. Required fields are marked *

eleven − 11 =