forked from starrohan999/Hacktoberfest-Accepted
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2D ARRAY.java
44 lines (36 loc) · 904 Bytes
/
2D ARRAY.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
import java.util.Scanner;
public class C {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n =s.nextInt();
int[][] ar = new int[n][n];
int z;
for( int i=0;i<n;i++){
for( int j=0;j<n;j++)
{
z = s.nextInt();
ar[i][j]=z;
}
}
int sum = 0;
int sum1 = 0;
for( int t=0;t<n;t++){
for( int r=0;r<n;r++)
{
if (t == r)
sum = sum + ar[t][r];
if ((t + r) == (n - 1))
sum1 = sum1 + ar[t][r];
}
}
int SUM = sum-sum1;
int q;
if(SUM<0)
{
q = -(SUM);
}
else
q = SUM;
System.out.print(""+q);
}
}