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 发布
此博客展示了如何使用Java编程语言实现一个程序,该程序接收用户输入的4x4矩阵,并计算矩阵元素的总和,最后输出计算结果。
704

被折叠的 条评论
为什么被折叠?



