Page 398 - CA_Blue( J )_Class10
P. 398

To create an array of 10 elements. Accept the index position and delete the number in the
                Program 16
                              position by using deletion logic.

                 1  import java.util.*;
                 2  class deletion_logic

                 3  {

                 4      public static void main()
                 5      {

                 6          Scanner sc= new Scanner (System.in);
                 7          int ar[]=new int[10];

                 8          int i,j,n,pos;
                 9          for (i=0; i<10; i++)

                10          {   System.out.print("Enter a number : ");
                11              ar[i] =sc.nextInt();

                12          }
                13          System.out.println("Enter a position to delete the number: ");
                14          pos=sc.nextInt();

                15          if(pos>=0 && pos<=9)

                16          {
                17              for (i=pos; i<9; i++)
                18              {      ar[i]=ar[i+1];

                19              }
                20              ar[9]=0;

                21          }
                22          for (i=0; i<9; i++)

                23          {      System.out.print(ar[i]+ " ");     }
                24      }

                25  }

              You will get the following output:
              Enter a number : 5
              Enter a number : 10
              Enter a number : 15
              Enter a number : 20
              Enter a number : 25
              Enter a number : 30
              Enter a number : 35
              Enter a number : 40


                396396  Touchpad Computer Applications-X
   393   394   395   396   397   398   399   400   401   402   403