diff --git a/MatrixExample.java b/MatrixExample.java index 051e5bc..a1ceb63 100644 --- a/MatrixExample.java +++ b/MatrixExample.java @@ -20,7 +20,7 @@ public static void main(String[] args) { System.out.println("result length: " + result.length + " x " + result[0].length); for (int i = 0; i < result.length; i++) { - for (int j = 0; j < result[i].length; i++) { + for (int j = 0; j < result[i].length; j++) { System.out.print(result[i][j] + " "); } System.out.println(); @@ -40,13 +40,13 @@ public static int[][] multiplyMatrices(int[][] matrix1, int[][] matrix2) { } // Some more issues here too - int[][] result = new int[rows1+1][cols2+1]; + int[][] result = new int[rows1][cols2]; // Lots of issues with this code, it used to be working perfectly though for (int i = 0; i < rows1; i++) { for (int j = 0; j < cols2; j++) { for (int k = 0; k < cols1; k++) { - result[j][k] += matrix1[i][j] * matrix2[k][j]; + result[i][j] += matrix1[i][k] * matrix2[k][j]; } } }