Page 502 - Cs_withBlue_J_C11_Flipbook
P. 502

Program 7      Define a class rowcolsum and print the row wise and column wise sum of the array.
                               int ar[][]                      :  to store array values
                               int m,n                         :  to store number of rows and columns
                               Members Functions

                               void row_sum()                  :  to find row wise sum of the array
                               void col_sum()                  :   to find the column wise sum of the array
                               Write a main method to call the methods and print the row and column wise sum of the
                               array.

                 1       import java.util.*;

                 2       class rowcolsum
                 3       {

                 4           int ar[][];
                 5           int m,n;

                 6
                 7           void input()

                 8           {
                 9               Scanner sc= new Scanner(System.in);

                10               int i,j;
                11               System.out.print("Number of rows : ");

                12               m=sc.nextInt();
                13               System.out.print("Number of column : ");

                14               n=sc.nextInt();
                15               ar=new int[m][n];

                16               //creation of array
                17               for(i=0;i<m;i++)

                18               {
                19                   for(j=0;j<n;j++)

                20                   {
                21                       System.out.print("Enter the element in the array : ");
                22                       ar[i][j]=sc.nextInt();

                23                   }

                24               }
                25           }
                26

                27           void row_sum()




                500500  Touchpad Computer Science-XI
   497   498   499   500   501   502   503   504   505   506   507