-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathDiagonalDifference.java
More file actions
38 lines (36 loc) · 912 Bytes
/
Copy pathDiagonalDifference.java
File metadata and controls
38 lines (36 loc) · 912 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
36
37
38
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
int n;
Scanner in=new Scanner(System.in);
n=in.nextInt();
int a[][]=new int[n][n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
a[i][j]=in.nextInt();
}
}
int pd=0,npd=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(j==i)
pd=pd+a[i][j];
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==n-j-1){
npd=npd+a[i][j];
}
}
}
int dif=npd-pd;
dif=Math.abs(dif);
System.out.println(dif);
}
}