题解 | #矩阵乘法#
矩阵乘法
https://www.nowcoder.com/practice/ebe941260f8c4210aa8c17e99cbc663b
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNext()) { // 注意 while 处理多个 case int x = in.nextInt(); int y = in.nextInt(); int z = in.nextInt(); int[][] xy = new int[x][y]; int[][] yz = new int[y][z]; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { xy[i][j] = in.nextInt(); } } for (int i = 0; i < y; i++) { for (int j = 0; j < z; j++) { yz[i][j] = in.nextInt(); } } for(int i =0;i<x;i++){ for(int j=0;j<z;j++){ int sum = 0; for(int k=0;k<y;k++){ sum+=xy[i][k]*yz[k][j]; } System.out.print(sum+" "); } System.out.println(); } } } }