Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Added: Dec 13, 2020 6:35 PM
Views: 3
Tags: twodimarray
  1. //If the sum of the Row is the same as one of the rows, then it's magic!
  2.     public static boolean isRowMagic(int[][] a) {
  3.  
  4.         int sumFirstRow = 0;
  5.         int secondRow = 0;
  6.         for (int i = 0; i < a[0].length; i++) {
  7.             sumFirstRow += a[0][i];
  8.         }
  9.  
  10.         for (int i = 0; i < a[1].length; i++) {
  11.             secondRow += a[1][i];
  12.  
  13.         }
  14.         if(sumFirstRow!=secondRow){
  15.             return false;
  16.         }
  17.  
  18.         return true;
  19.     }