Class matrix2 1/1
1 import java.util.*;
2 class matrix2
3 {
4 public static void main()
5 {
6 Scanner sc=new Scanner(System.in);
7 System.out.println("Enter the number of row and column");
8 int m=sc.nextInt();
9 int n=sc.nextInt();
10 int a[][]=new int [m][n];
11 int i,j,sum=0;
12 System.out.println("Enter the elements of the array ");
13 for(i=0;i<m;i++)
14 {
15 for(j=0;j<n;j++)
16 {
17 a[i][j]=sc.nextInt();
18 }
19 }
20 System.out.println("addition of row is");
21 for(i=0;i<m;i++)
22 {
23 sum=0;
24 for(j=0;j<n;j++)
25 {
26 System.out.print(a[i][j]+"\t");
27 sum=sum+a[i][j];
28 }
29 System.out.print(sum);
30 System.out.println();
31 }
32 int sum1;
33 for(i=0;i<n;i++)
34 {
35 sum1=0;
36 for(j=0;j<m;j++)
37 {
38 sum1=sum1+a[j][i];
39 }
40 System.out.print(sum1+"\t");
41 }
42 }
43 }
Sep 5, 2021 9:30:28 AM