Page 296 - Computer science 868 Class 12
P. 296

30               {
                31                   a[i-1] = a[i];

                32               }
                33               a[n-1] = 0;
                34           }

                35

                36           void display()
                37           {
                38               for(int i = 0; i < n-1; i++)

                39               {
                40                   System.out.print(a[i]+",");

                41               }
                42               System.out.print(a[n-1]);

                43           }
                44

                45           public static void main(String[] args)
                46           {

                47               Delete_Array ob= new Delete_Array();
                48               ob.input();

                49               System.out.println("Before deletion");
                50               ob.display();

                51               ob.remove_element();
                52               System.out.println("\nAfter deletion");

                53               ob.display();
                54           }

                55       }

              The output of the preceding program is as follows:
              Enter no. of elements you want in array:5
              Enter all the elements:

              1 2 3 4 5
              Enter the position from where you want to delete element:3
              Before deletion
              1,2,3,4,5

              After deletion
              1,2,3,5,0



                294294  Touchpad Computer Science-XII
   291   292   293   294   295   296   297   298   299   300   301