题解 | #矩阵乘法#
矩阵乘法
https://www.nowcoder.com/practice/ebe941260f8c4210aa8c17e99cbc663b
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner fzhinput = new Scanner(System.in); int h1 = fzhinput.nextInt(); int l1 = fzhinput.nextInt(); int h2 = l1; int l2 = fzhinput.nextInt(); int jz1[][] = new int[h1][l1]; int jz2[][] = new int[h2][l2]; int jz3[][] = new int[h1][l2]; for (int i = 0; i < h1; i++) { for (int j = 0; j < l1; j++) { jz1[i][j] = fzhinput.nextInt(); } } for (int i = 0; i < h2; i++) { for (int j = 0; j < l2; j++) { jz2[i][j] = fzhinput.nextInt(); } } for (int i = 0; i < h1; i++) { for (int j = 0; j < l2; j++) { for (int z = 0; z < l1; z++) { jz3[i][j] += jz1[i][z] * jz2[z][j]; } } } for (int i = 0; i < h1; i++) { for (int j = 0; j < l2; j++) { System.out.print(jz3[i][j]+" "); } System.out.println(); } } }