RandomProblem003 { public static int[][] matrixMultiplication(int[][] a, int[][] b) { int rowsA = a.length; int colsA = a[0].length; int rowsB = b.length; int colsB = b[0].length; if (colsA != rowsB) { throw new IllegalArgumentException("Can't perform matrix calculation on matrix with given sizes"); } int[][] result = new int[rowsA][colsB]; for (int i = 0; i < rowsA; i++) { for (int j = 0; j < colsB; j++) { int fValue = 0; for (int k = 0; k < colsA; k++) { fValue += a[i][k] * b[k][j]; } result[i][j] = fValue; } } return result; }  static int[][] matrixMultiplication(int[][] a, int[][] b);  }
@Test public void performMatrixMultiplicationOfTwoArrays() throws Exception { int[][] a = { {1, 2, 3}, {4, 5, 6} }; int[][] b = { {7, 8}, {9, 10}, {11, 12} }; int[][] result = { {58, 64}, {139, 154} }; int[][] c = RandomProblem003.matrixMultiplication(a, b); assertThat(c, equalTo(result)); }