You are viewing a single comment's thread. Return to all comments →
More simple. Without an array
public static void main(String[] args) { int pSum = 0, sSum = 0, N, input; Scanner in = new Scanner(System.in); N = in.nextInt(); for(int i = 0; i < N; i ++){ for(int j = 0; j < N; j++){ input = in.nextInt(); if(i == j){ pSum += input; } if(j == N-(i+1)){ sSum += input; } } } System.out.println(Math.abs(pSum-sSum)); }
Seems like cookies are disabled on this browser, please enable them to open this website
Diagonal Difference
You are viewing a single comment's thread. Return to all comments →
More simple. Without an array