Define a class to accept values in integer array of size 10. Sort them in an ascending order
using selection sort technique. Display the sorted array.
        
Solution:
,
 

  import java.util.*;
  class selection
  {
      public static void main(String args[])
      {
          int arr[];
          arr=new int[10];
          Scanner sc=new Scanner(System.in);
          System.out.println("Enter 10 numbers");
          for(int i=0;i < 10;i++)
          {
              arr[i]=sc.nextInt();
          }
          System.out.println("Original array:");
          for(int i=0;i < 10;i++)
          {
              System.out.print(arr[i]+" ");
          }
          for(int i=0;i < 10;i++) 
          {
              int index = i;
              for(int j= i+1;j < 10;j++) 
              {
                  if(arr[j] < arr[index])
                  {
                  index = j; 
                  }  
              } 
              int temp = arr[i];  
              arr[i] = arr[index];  
              arr[index] = temp;
          }
          System.out.println("Sorted array:");
          for(int i=0;i < 10;i++)
          {
              System.out.print(arr[i]+" ");
          }
      }
  }
          

                                          
  
                                              
          
                                                                  


                                            



Contact Us

REACH US

SERVICES

  • CODING
  • ON-LINE PREPARATION
  • JAVA & PYTHON

ADDRESS

B-54, Krishna Bhawan, Parag Narain Road, Near Butler Palace Colony Lucknow
Contact:+ 919839520987
Email:info@alexsir.com