Advertisement
Ivan18113

MatrixSum

Feb 15th, 2021
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class App7 {
  4.     public static void main(String[] args) {
  5.         int[][] matrix ={
  6.                 {1,2,3},
  7.                 {4,5,6},
  8.                 {7,8,9}
  9.         };
  10.         int sum = 0;
  11.         for (int row = 0; row < matrix.length; row++) {
  12.             int[] currentRow = matrix[row];
  13.             for (int cols = 0; cols < currentRow.length; cols++) {
  14.                 sum+=currentRow[cols];
  15.             }
  16.         }
  17.         System.out.println("MatrixSum: "+ sum);
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement