数组arr1[x][y] 乘以arr2[y][z]-----会得到数组result[x][z]
数组计算公式:
result[i][j]===arr1的第i行乘以arr2的第j列的乘积的和
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
int x=sc.nextInt();
int y=sc.nextInt();
int z=sc.nextInt();
int[][] arr1=new int[x][y];
int[][] arr2=new int[y][z];
for(int i=0;i<x;i++){
for(int j=0;j<y;j++){
arr1[i][j]=sc.nextInt();
}
}
for(int i=0;i<y;i++){
for(int j=0;j<z;j++){
arr2[i][j]=sc.nextInt();
}
}
result( arr1,arr2,x,y,z);
}
sc.close();
}
public static void result(int arr1[][],int arr2[][],int x,int y,int z){
int[][] arrResult=new int[x][z];
for(int i=0;i<x;i++){
// int result=0;
for(int j=0;j<z;j++){
int result=0;
for(int k=0;k<y;k++){
//arrResult[i][j]=arr1[i][k]*arr2[k][j];
result+=arr1[i][k]*arr2[k][j];
}
arrResult[i][j]=result;
if(j==z-1){
System.out.println(arrResult[i][z-1]);
}else{
System.out.print(arrResult[i][j]+" ");
}
}
}
}
}