Q:

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

0

Program to implement Selection Sorting by taking input from the user using for loop, temporary user input.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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]+ "  ");  
       }  
   }  
} 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now