Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package exercise.pkg7.pkg1;
- import java.util.*;
- public class Exercise71 {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int[][] m = new int[4][4];
- System.out.println("Enter a 4-by-4 matrix row by row: ");
- for (int i=0; i<4; i++)
- {
- for(int j=0;j<4;j++)
- {
- m[i][j] = input.nextInt();
- }
- }
- System.out.println("The sum if the matrix is " + sumMatrix(m));
- }
- public static double sumMatrix(int[][] m) {
- int total = 0;
- int row = 0;
- int column = 0;
- for (row = 0; row < 4; row++){
- for (column = 0; column < 4; column++){
- total += m[row][column];
- }
- }
- return total;
- }
- }
Add Comment
Please, Sign In to add comment