-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrixsumofrowsandcolumns.java
More file actions
42 lines (40 loc) · 1.01 KB
/
matrixsumofrowsandcolumns.java
File metadata and controls
42 lines (40 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.util.Scanner;
class matrixsumofrowsandcolumns
{
public static void main(String[] args)
{
System.out.println("Enter the size of rows and columns of the array");
int sizeofrow=new Scanner(System.in).nextInt();
int sizeofcol=new Scanner(System.in).nextInt();
int a[][]=new int [sizeofrow][sizeofcol];
int b[][]=new int [sizeofrow][sizeofcol];
System.out.println("Enter array elements");
for(int row=0;row<sizeofrow;row++)
{
for (int col=0;col<sizeofcol;col++)
{
a[row][col]=new Scanner(System.in).nextInt();
}
}
for(int row=0;row<sizeofrow;row++)
{
int sum=0;
System.out.print("Sum of row " + (row+1) + " is->");
for (int col=0;col<sizeofcol;col++)
{
sum+=a[row][col];
}
System.out.println(sum);
}
for (int col=0;col<sizeofcol;col++)
{
int sum=0;
System.out.print("Sum of column " + (col+1) + " is->");
for(int row=0;row<sizeofrow;row++)
{
sum+=a[row][col];
}
System.out.println(sum);
}
}
}