1 import java.util.Scanner; 2 public class Main{ 3 public static void main(String[] args){ 4 Scanner scanner=new Scanner(System.in); 5 int row=scanner.nextInt(); 6 int len=scanner.nextInt(); 7 int column=scanner.nextInt(); 8 int [][] x1=new int[row][len]; 9 int [][] x2=new int[len][column]; 10 for(int i=0;i<row;i++) 11 { 12 for(int j=0;j<len;j++) 13 { 14 x1[i][j]=scanner.nextInt(); 15 } 16 } 17 for(int i=0;i<len;i++) 18 { 19 for(int j=0;j<column;j++) 20 { 21 x2[i][j]=scanner.nextInt(); 22 } 23 } 24 int [][]d=matrixMultity(x1, x2); 25 for(int i=0;i<row;i++) 26 { 27 for(int j=0;j<column;j++) 28 { 29 if(j==column-1) 30 System.out.print(d[i][j]); 31 else 32 System.out.print(d[i][j]+" "); 33 } 34 System.out.println(); 35 } 36 scanner.close(); 37 } 38 39 /** 40 * 41 * @param x1 42 * @param x2 43 * @return 44 */ 45 public static int [][] matrixMultity(int [][] x1,int[][] x2) 46 { 47 int row=x1.length,column=x2[0].length; 48 int len=x1[0].length; 49 int [][] d=new int[row][column]; 50 for(int i=0;i<row;i++) 51 { 52 for(int j=0;j<column;j++) 53 { 54 int sum=0; 55 for(int k=0;k<len;k++) 56 { 57 sum+=x1[i][k]*x2[k][j]; 58 } 59 d[i][j]=sum; 60 } 61 } 62 return d; 63 } 64 }
时间: 2024-10-16 05:44:11