Page 470 - Cs_withBlue_J_C11_Flipbook
P. 470

package Orange_prog
                    import Eleven.Sort;
                    import java.util.*;
                    class Second
                    {
                      int size,arr[];
                      void accept()
                      {
                          Scanner sc=new Scanner(System.in);
                          System.out.println("Enter size");
                          size=sc.nextInt();
                          arr=new int[size];
                          System.out.println("Enter numbers in array");
                          for(int i=0;i<size;i++)
                          {
                              arr[i]=sc.nextInt();
                          }
                       }
                     void print()
                     {
                          Sort ob=new Sort(size,arr);
                          arr=ob.bubble();
                         System.out.println("Sorted array in ascending order");
                         for(int i=0;i<size;i++)
                          {
                              System.out.print(arr[i]+" ");
                          }
                         System.out.println("\nSecond lowest "+arr[1]);
                         System.out.println("Second highest "+arr[size-2]);
                    }
                    public static void main()
                    {
                      Second ob=new Second();
                       ob.accept();
                       ob.print();
                    }
                    }
                    The output of the preceding program is as follows:
                     Enter size
                     5
                     Enter numbers in array
                     34
                     12
                     7
                     89
                     54
                     Sorted array in ascending order
                     7 12 34 54 89
                     Second lowest 12
                     Second highest 54





                468468  Touchpad Computer Science-XI
   465   466   467   468   469   470   471   472   473   474   475