Page 576 - ComputerScience_Class_11
P. 576

Program 8      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()





                  574  Touchpad Computer Science (Ver. 3.0)-XI
   571   572   573   574   575   576   577   578   579   580   581