Advertisement
eldieck

matrixElementSum

Jul 11th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.35 KB | None | 0 0
  1. int matrixElementsSum(int[][] matrix) {
  2.         int[] zeroInColumn = new int[matrix[0].length];
  3.         int sum = 0;
  4.         for (int i = 0; i < matrix.length; i++) {
  5.             for (int j = 0; j < matrix[i].length; j++) {
  6.                 if (matrix[i][j] == 0) {
  7.                     zeroInColumn[j] = 1;
  8.                 }
  9.  
  10.                 if (zeroInColumn[j] != 1) {
  11.                     sum += matrix[i][j];
  12.                 }
  13.             }
  14.         }
  15.         return sum;
  16.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement