I hope this will help:- Code: public static void mmult (int rows, int cols, int[][] m1, int[][] m2, int[][] m3) { for (int i=0; i<rows; i++) { for (int j=0; j<cols; j++) { int val = 0; for (int k=0; k<cols; k++) { val += m1[i][k] * m2[k][j]; } m3[i][j] = val; } } }