/* In the following Java program, we ask user to enter the array elements or number, 
then we compare the array's element and start swapping with the variable temp. 
Put the first element in the temp and the second element in the first, 
and then temp in the second number and continue for the next match to sort the whole
array in ascending order. */

import java.util.Scanner;  
  
public class SelectionSortExample2  
{  
   public static void main(String args[])  
   {  
       int size, i, j, temp;  
       int arr[] = new int[50];  
       Scanner scan = new Scanner(System.in);  
         
       System.out.print("Enter Array Size : ");  //  size of array taken from user.
       size = scan.nextInt();  
         
       System.out.print("Enter Array Elements : ");  
       for(i=0; i<size; i++)  
       {  
           arr[i] = scan.nextInt();  // enter elements in array.
       }  
         
       System.out.print("Sorting Array using Selection Sort Technique..\n");  
       for(i=0; i<size; i++)  
       {  
           for(j=i+1; j<size; j++)  
           {  
               if(arr[i] > arr[j])  
               {  
                   temp = arr[i];  
                   arr[i] = arr[j];  
                   arr[j] = temp;  
               }  
           }  
       }  
         
       System.out.print("Now the Array after Sorting is :\n");  
       for(i=0; i<size; i++)  
       {  
           System.out.print(arr[i]+ "  ");  // printing the sorted array.
       }  
   }  
}  
