import java.util.Scanner;
public class Test
{
public static void main(String[] args)
{
System.out.println("Enter a 4-by-4 matrix row by row: ");
Scanner input = new Scanner(System.in);
int[][] number = new int[4][4];
for(int i = 0; i < number.length; i++)
for(int j = 0; j < number[i].length; j++)
number[i][j] = input.nextInt();
System.out.println("Sum of the matrix is " + sumMatrix(number));
}
public static double sumMatrix(int[][] m)
{
int total = 0;
for(int row = 0; row < m.length; row++)
for(int column = 0; column < m[row].length; column++)
total += m[row][column];
return total;
}
}
7-1 编程练习题答案
最新推荐文章于 2023-05-14 21:22:26 发布