我编写了这个代码用于乘以两个矩阵,但我如何在main函数中给它参数?
public static int [][] multiply(int[][] a, int[][] b){
int[][] p = new int [a.length][a[0].length];
for (int i = 0; i < a.length; i++)
for (int j = 0; j < a[0].length; j++) {
p[i][j] = 0;
for (int k = 0; k < a[0].length; k++)
p[i][j] += a[i][k] * b[k][j];
}
return p;
}
答案 0 :(得分:1)
int[][] a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int[][] b = {{9, 8, 7}, {6, 5, 4}, {3, 2, 1}};
int[][] c = MatrixClass.multiply(a, b); // your multiplied array coming from your MatrixClass
答案 1 :(得分:0)
int[][] c = multiply( new int[][]{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
},
new int[][]{
{9, 8, 7},
{6, 5, 4},
{3, 2, 1}
});