Guest User

Untitled

a guest
Jan 21st, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. package exercise.pkg7.pkg1;
  2. import java.util.*;
  3.  
  4. public class Exercise71 {
  5.  
  6. public static void main(String[] args) {
  7. Scanner input = new Scanner(System.in);
  8. int[][] m = new int[4][4];
  9. System.out.println("Enter a 4-by-4 matrix row by row: ");
  10. for (int i=0; i<4; i++)
  11. {
  12. for(int j=0;j<4;j++)
  13. {
  14. m[i][j] = input.nextInt();
  15. }
  16. }
  17.  
  18. System.out.println("The sum if the matrix is " + sumMatrix(m));
  19. }
  20.  
  21. public static double sumMatrix(int[][] m) {
  22. int total = 0;
  23. int row = 0;
  24. int column = 0;
  25.  
  26. for (row = 0; row < 4; row++){
  27. for (column = 0; column < 4; column++){
  28. total += m[row][column];
  29. }
  30. }
  31.  
  32. return total;
  33. }
  34. }
Add Comment
Please, Sign In to add comment