Selection Sort in Descending Order Java

 Selection Sort in Descending Order Java

Selection Sort in Descending Order Java

Here is  the  Selection Sort in Descending Order Java

We are uploading these types of program. However, if you need fully compiled solution of any type of Java program then simply leave a comment below, we will help you at the earliest. 😊😊

 import java.util.*;  
 class Selecton_Sort_Descending_Order  
 {  
   public static void main()  
   {  
     Scanner sc=new Scanner(System.in);  
     System.out.println("Enter the size of the array:-");  
     int n=sc.nextInt();  
     System.out.println("Enter the elements of array:-");  
     int b[]=new int[n];  
     for (int i=0;i<n; i++)  
       b[i]=sc.nextInt();  
     for(int i=0;i<n-1;i++)  
     {  
       int smallest=b[i],pos=i;  
       for(int j=i+1;j<n;j++)  
       {  
         if(b[j]<smallest)  
         {  
           smallest=b[j];  
           pos=j;  
         }  
       }  
       b[pos]=b[i];  
       b[i]=smallest;  
     }  
     System.out.println("Elements after Sorting:-");  
     for (int i=0;i<n;i++)  
       System.out.println(b[i]+" ");  
   }  
 }  
 -------------  
 OUTPUT:-  
 -------------  
 Enter the size of the array:-  
 5  
 Enter the elements of array:-  
 2  
 5  
 6  
 3  
 1  
 Elements after Sorting:-  
 6  
 5  
 3  
 2  
 1  
 ------------------------  

Checkout:- Find Transpose of a Matrix

Checkout:-  Program to Find the Sum of Each Row and Each Column of Matrix

Post a Comment

0 Comments