package homwk; import java.util.Arrays; import java.util.Scanner; public class hmwk6 { public static void main(String[] args) { @SuppressWarnings("resource") Scanner input = new Scanner(System.in); final int N = 3; double a[][] = new double[N][N]; double b[][] = new double[N][N]; double c[][] = new double[N][N]; for(int i = 0;i<a.length;i++) { for(int j = 0;j<a[i].length;j++) { a[i][j] = input.nextDouble(); } } for(int i = 0;i<b.length;i++) { for(int j = 0;j<b[i].length;j++) { b[i][j] = input.nextDouble(); } } for(int i = 0;i<a.length;i++) { for(int j = 0;j<a.length;j++) { for(int k = 0;k<a.length;k++) { c[i][j] += a[i][k]*b[k][j]; } } } System.out.println("输出矩阵相乘得到的矩阵c:"); for(int i = 0;i<c.length;i++) { for(int j = 0;j<c.length;j++) { System.out.printf("%.1f",c[i][j]); if(j == 4) { System.out.println(); } else { System.out.print(","); } } } public static void sort0( int m[][]) { for (int k = 0; k < m.length; k++) { Arrays.sort(m[k]); } for (int i = 0; i < m.length; i++) { for (int j = 0; j < m[i].length; j++) { System.out.print(m[i][j] + " "); } System.out.println(); } } }