题目要求
解题思路
这个题老老实实的把矩阵存进来,然后相乘。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int m, s, n, i, j, k;
m = in.nextInt();
s = in.nextInt();
n = in.nextInt();
int[][] a = new int[m][s];
int[][] b = new int[s][n];
int[][] c = new int[m][n];
for (i = 0; i < m; i++) {
for (j = 0; j < s; j++) {
a[i][j] = in.nextInt();
}
}
for (i = 0; i < s; i++) {
for (j = 0; j < n; j++) {
b[i][j] = in.nextInt();
}
}
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
c[i][j] = 0;
for (k = 0; k < s; k++) {
c[i][j] += a[i][k] * b[k][j];
}
System.out.print(c[i][j] + " ");
}
System.out.println();
}
}
}