Java

Program to implement Selection Sorting by taking input from the user.

Program to implement Selection Sorting by taking input from the user.
import java.util.Scanner;  
public class demo1  
{  
   public static void main(String args[])  
   {  
       int arrSize, a, b, temp1;  
       int array[] = new int[50];  
       Scanner input = new Scanner(System.in);  
         
       System.out.print("Enter Array Size : ");  
       arrSize = input.nextInt();  
         
       System.out.print("Enter Array Elements : ");  
       for(a=0; a<arrSize; a++)  
       {  
           array[a] = input.nextInt();  
       }          
       for(a=0; a<arrSize; a++)  
       {  
           for(b=a+1; b<arrSize; b++)  
           {  
               if(array[a] > array[b])  
               {  
                   temp1 = array[a];  
                   array[a] = array[b];  
                   array[b] = temp1;  
               }  
           }  
       }  
         
       System.out.print("Now the Array after Sorting is :\n");  
       for(a=0; a<arrSize; a++)  
       {  
           System.out.print(array[a]+ "  ");  
       }  
   }  
} 
Nikhil Juneja

Passionate software developer and technical contributor at TutorialsLink.