1. Calculated two matrices where the number of columns in the first matrix must be the same as the number of rows in the second matrix;
2. The number of rows in the first matrix determines the number of rows in the result matrix, and the number of columns in the second matrix determines the number of columns in the result matrix;
1 PackageOrg.admln.matrix;2 /*3 * 201502114 */5 Public classmatrixmultiplication {6 Public Static voidMain (string[] args) {7 /*8 * 1. Build the Matrix9 * 2 9 7 4 2Ten * matrix1= 3 1 4 matrix2= 6 8 One * 2 6 A */ - int[] matrix1 = {{2,9,7},{3,1,4}}; - int[] matrix2 = {{4,2},{6,8},{2,6}}; theSystem.out.println ("matrix1 matrix is" + Matrix1.length + "Row" + matrix1[0].length + "column"); - for(inti=0;i<matrix1.length;i++) { - for(intj=0;j<matrix1[i].length;j++) { -System.out.print ("\ T" +matrix1[i][j]); + } - System.out.println (); + } ASystem.out.println ("matrix2 matrix is" + Matrix2.length + "Row" + matrix2[0].length + "column"); at for(inti=0;i<matrix2.length;i++) { - for(intj=0;j<matrix2[i].length;j++) { -System.out.print ("\ T" +matrix2[i][j]); - } - System.out.println (); - } in /* - * 2. Multiply matrix to */ +SYSTEM.OUT.PRINTLN ("Result matrix is" + Matrix1.length + "Row" + matrix2[0].length + "column"); - for(inti=0;i<matrix1.length;i++) { the for(intj=0;j<matrix2[0].length;j++) { * intsum = 0; $ for(intk=0;k<matrix2.length;k++) {Panax NotoginsengSum + = matrix1[i][k] *Matrix2[k][j]; - } theSystem.out.print ("\ T" +sum); + } A System.out.println (); the } + } -}
Java Simple matrix multiplication operation