-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumEachRow.java
More file actions
35 lines (33 loc) · 933 Bytes
/
SumEachRow.java
File metadata and controls
35 lines (33 loc) · 933 Bytes
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
// Program: Calculate Sum of Each Row in a 2D Array
// Topic: 2D Arrays and Loops
// Description: Reads a 4x4 integer matrix from user input, then calculates and displays
// the sum of elements in each row using nested loops.
package Array2D;
import java.util.*;
/**
*
* @author Samim
*/
public class SumEachRow
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int ar[][]=new int [4][4];
for (int[] ar1 : ar) {
for (int j = 0; j<ar.length; j++) {
ar1[j] = sc.nextInt();
}
}
//Printing Sum Of Each Row
for(int i=0;i<ar.length;i++)
{
int sum=0;
for(int j=0;j<ar.length;j++)
{
sum+=ar[i][j];
}
System.out.println("Sum Of Row :"+(i+1)+" "+sum);
}
}
}