Page 236 - CA_Blue( J )_Class10
P. 236

To input 10 elements in an array, increase the numbers by two and copy the element in the second
                Program 4
                             array using function copyelement(int [], int[]).
                 1  import java.util.*;

                 2  class impure_method
                 3  {

                 4      void copyelement(int ar1[], int ar2[])
                 5      { int i;

                 6          for (i=0; i<ar1.length; i++)
                 7          { ar2[i]=ar1[i]+2; }

                 8      }
                 9      public static void main ()

                10      {
                11          Scanner sc= new Scanner (System.in);

                12          impure_method obj = new impure_method();
                13          int array1[] =new int [10];

                14          int array2[] =new int [10];
                15          int i;

                16          System.out.println("Enter elements in the first array:");
                17          for (i=0; i<10; i++)

                18          {
                19              array1[i]=sc.nextInt();

                20          }
                21          obj.copyelement(array1, array2);

                22          System.out.println("Elements in the second array:");
                23          for(i=0;i<10;i++)

                24          {
                25              System.out.print(array2[i]+ " ");
                26          }

                27      }

                28  }











                234234  Touchpad Computer Applications-X
   231   232   233   234   235   236   237   238   239   240   241