标签:
1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 double[][] matrix = new double[4][4]; 9 System.out.print("Enter a 4-by-4 matrix row by row: "); 10 for(int i = 0; i < 4; i++) 11 for(int j = 0; j < 4; j++) 12 matrix[i][j] = input.nextDouble(); 13 14 input.close(); 15 System.out.println("Sum of the matrix is " + sumMatrix(matrix)); 16 } 17 18 public static double sumMatrix(double[][] m) 19 { 20 double sum = 0; 21 for(double[] i: m) 22 for(double j: i) 23 sum += j; 24 return sum; 25 } 26 }
标签:
原文地址:http://www.cnblogs.com/wood-python/p/5819126.html