class Main {
public static void main(String[] args) {
int[][] mat1 = {
{1, 3, 5},
{2, 4, 1}
};
int[][] mat2 = {
{2, 3},
{1, 5},
{3, 6}
};
int[][] ans = matrixMultiplication(mat1, mat2);
for (int i = 0; i < ans.length; ++i) {
for (int j = 0; j < ans[i].length; ++j) {
System.out.print(ans[i][j] + " ");
}
System.out.println();
}
}
public static int[][] matrixMultiplication(int[][] mat1, int[][] mat2) {
// 从下面开始写代码
int[][] ans=new int [mat1.length][mat2[0].length];
for(int i=0;i<mat1.length;i++){
for(int j=0;j<mat2[0].length;j++){
for(int k=0;k<mat2.length;k++){
ans[i][j]+=mat1[i][k]*mat2[k][j];
}
}
}
return ans;
}
}
网友评论