Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Added: Dec 13, 2020 7:12 PM
Views: 3
Tags: twodimarray
  1.  public static boolean isDiagonalMagic(int[][] a){
  2.         int diagonalL2R = 0;
  3.         int length = a.length;
  4.         int diagonalR2L = 0;
  5.  
  6.         for (int i = 0; i < a.length; i++) {
  7.             diagonalL2R += a[i][i];
  8.         }
  9.         for (int i = 0; i < a.length; i++) {
  10.             for (int j = length - 1; j >= 0 ; j -= length) {
  11.                 diagonalR2L += a[i][j];
  12.             }
  13.  
  14.         }
  15.         if (diagonalL2R == diagonalR2L) {
  16.             return true;
  17.         }
  18.         return false;
  19.     }