Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MultidimensionalArrays2;
- import java.util.Scanner;
- public class DiagonalDifference {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int matrixSize = Integer.parseInt(scanner.nextLine());
- int[][] matrix = new int[matrixSize][matrixSize];
- int sum = 0; int sum2 = 0;
- for (int row = 0; row < matrixSize; row++) {
- String[] line = scanner.nextLine().split(" ");
- for (int col = 0; col < matrixSize; col++) {
- matrix[row][col] = Integer.parseInt(line[col]);
- }
- }
- for (int col = 0; col < matrixSize; col++) {
- sum = matrix[col][col] + sum;
- }
- for (int col = 0; col < matrixSize; col++) {
- sum2 = matrix[col][matrixSize-1-col] + sum2;
- }
- if (sum>sum2){
- System.out.println(sum-sum2);
- }else {
- System.out.println(sum2-sum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement