以下是必需的程序。
public class Tester { public static void main(String args[]) { //矩阵1- int a[][] = { { 1, 3, 4 }, { 2, 4, 3 }, { 3, 4, 5 } }; //矩阵2- int b[][] = { { 1, 3, 4 }, { 2, 4, 3 }, { 1, 2, 4 } }; //结果矩阵 int c[][] = new int[3][3]; // 3 rows and 3 columns //乘法并打印矩阵 for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { c[i][j] = 0; for (int k = 0; k < 3; k++) { c[i][j] += a[i][k] * b[k][j]; } System.out.print(c[i][j] + " "); } System.out.println(); } } }
输出结果
11 23 29 13 28 32 16 35 44