-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDiagDiff.java
More file actions
32 lines (25 loc) · 742 Bytes
/
DiagDiff.java
File metadata and controls
32 lines (25 loc) · 742 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
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int diff;
int n = sc.nextInt(), i, j;
int nums[][] = new int[n][n];
for(i = 0; i < n; i++) {
for(j = 0; j < n; j++) {
nums[i][j] = sc.nextInt();
}
}
int diagLeft = 0, diagRight = 0;
for(i = 0; i < n; i++) {
j = i;
diagLeft += nums[i][j];
}
for(i = 0; i < n; i++) {
j = n - i - 1;
diagRight += nums[i][j];
}
System.out.println(Math.abs(diagLeft - diagRight));
}
}