Selection Sort (Descending)

Selection sort is a simple yet efficient sorting algorithm which checks for its all positions with other positions of data and if the sorting condition matches then it swaps the position of the values.

Here we used Selection Sort to sort an array in Descending order.

Java
import java.util.*;
public class SelectionSortAscending
{
    public static void main(String args[])
    {
        int size=0,temp=0;
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter array size: ");
        size=sc.nextInt();
        int ar[]=new int[size];
        System.out.println("Enter array elements:-");
        for(int i=0;i<size;i++)
        {
            ar[i]=sc.nextInt();
        }
        for(int i=0;i<size-1;i++)
        {
            for(int j=i+1;j<size;j++)
            {
                if(ar[i]<ar[j])
                {
                    temp=ar[i];
                    ar[i]=ar[j];
                    ar[j]=temp;
                }
            }
        }
        System.out.println("Sorted array:-");
        for(int i=0;i<size;i++)
        {
            System.out.println(ar[i]);
        }
    }
}
Java