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