-
Notifications
You must be signed in to change notification settings - Fork 0
/
YT46.java
58 lines (48 loc) · 1.19 KB
/
YT46.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//2d array
import java.io.*;
public class YT46
{
public static void main(String[] args)throws IOException
{
int a[][]=new int[4][4];
int sl=0, sr=0;
InputStreamReader I = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(I);
System.out.println("Enter the number in 4x4 matrix: ");
for(int i=0; i<4; i++)
{
for(int j=0; j<4; j++)
{
a[i][j]=Integer.parseInt(br.readLine());
}
}
for(int i=0; i<4; i++)
{
for(int j=0; j<4; j++)
{
if(i==j)
{
sl=sl+a[i][j];
}
}
}
for(int i=0; i<4; i++)
{
for(int j=0; j<4; j++)
{
if((i+j)==3)
{
sr=sr+a[i][j];
}
}
}
if(sl==sr)
{
System.out.println("Diagonal Array");
}
else
{
System.out.println(" NOT Diagonal Array");
}
}
}