Advertisement
deyanmalinov

04. Sum Matrix Elements

May 24th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. package DPM;
  2. import java.util.Scanner;
  3. public class Main {
  4.     public static void main(String[] args){
  5.         Scanner scan = new Scanner(System.in);
  6.         String[] fLine = scan.nextLine().split(", ");
  7.         int row = Integer.parseInt(fLine[0]);
  8.         int col = Integer.parseInt(fLine[1]);
  9.         int fullSum = 0;
  10.         int sum =0;
  11.         for (int i = 0; i < row; i++) {
  12.             fullSum +=sum;
  13.             String [] numLine = scan.nextLine().split(", ");
  14.             for (int j = 0; j < numLine.length; j++) {
  15.                 int num = Integer.parseInt(numLine[j]);
  16.                 sum += num;
  17.  
  18.             }
  19.  
  20.         }
  21.         System.out.println(row);
  22.         System.out.println(col);
  23.         System.out.println(sum);
  24.  
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement