-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYT15.java
More file actions
47 lines (42 loc) · 1.21 KB
/
YT15.java
File metadata and controls
47 lines (42 loc) · 1.21 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
43
44
45
46
47
import java.io.*;
class YT15
{
public static void main(String[] args)throws IOException
{
int a[][]= new int[4][4];
int sc=0;
int sr=0;
InputStreamReader I = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(I);
System.out.println("Enter the matrix 4x4: ");
for(int i=0; i<4; i++)
{
for(int j=0; j<4; j++)
{
a[i][j]=Integer.parseInt(br.readLine());
}
}
System.out.println("Original Array");
for(int i=0; i<4; i++)
{
for(int j=0; j<4; j++)
{
System.out.print(a[i][j]+ " ");
}
System.out.println();
}
System.out.println();
for(int i=0; i<4; i++)
{
for(int j=0; j<4; j++)
{
sr=sr+a[i][j];
sc=sc+a[j][i];
}
System.out.println("The sum of the elements of "+(i+1)+" row is: "+sr);
System.out.println("The sum of the elements of "+(i+1)+" col is: "+sc);
sc=0;
sr=0;
}
}
}