Page 396 - CA_Blue( J )_Class10
P. 396

11              ar[i] =sc.nextInt();
                12          }

                13          for(i=0;i<9;i++)
                14          {

                15              min=ar[i];
                16              minpos=i;

                17              for(j=i+1;j<10; j++)
                18              {   if(ar[j]<min)

                19                  {   min=ar[j];
                20                      minpos=j;      }

                21              }
                22              temp = ar[minpos];

                23              ar[minpos]=ar[i];
                24              ar[i]=temp;

                25          }
                26          for(i=0;i<10;i++)

                27          {   System.out.print(ar[i]+ " ");   }
                28      }

                29  }
              You will get the following output:
              Enter a number : 9
              Enter a number : 7
              Enter a number : 5
              Enter a number : 3
              Enter a number : 1
              Enter a number : 2
              Enter a number : 4
              Enter a number : 6
              Enter a number : 8
              Enter a number : 10
              1 2 3 4 5 6 7 8 9 10

                              To create an array of 20 elements and input 19 elements. Accept the index position to insert a
                Program 15
                              number in the array using insertion logic.

                 1  import java.util.*;
                 2  class insertion_logic

                 3  {




                394394  Touchpad Computer Applications-X
   391   392   393   394   395   396   397   398   399   400   401