forked from usamajay/hacktoberfest2021-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRowColumsum.java
37 lines (31 loc) · 969 Bytes
/
RowColumsum.java
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
public class SumofRowColumn
{
public static void main(String[] args) {
int rows, cols, sumRow, sumCol;
int a[][] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
rows = a.length;
cols = a[0].length;
for(int i = 0; i < rows; i++)
{
sumRow = 0;
for(int j = 0; j < cols; j++)
{
sumRow = sumRow + a[i][j];
}
System.out.println("Sum of " + (i+1) +" Row: " + sumRow);
}
for(int i = 0; i < cols; i++)
{
sumCol = 0;
for(int j = 0; j < rows; j++)
{
sumCol = sumCol + a[j][i];
}
System.out.println("Sum of " + (i+1) +" Column: " + sumCol);
}
}
}