diff --git a/OOP/Java/Lab/Week4/MatrixMulp.java b/OOP/Java/Lab/Week4/MatrixMulp.java index 765b5df..86f4f4b 100644 --- a/OOP/Java/Lab/Week4/MatrixMulp.java +++ b/OOP/Java/Lab/Week4/MatrixMulp.java @@ -44,29 +44,31 @@ class MatrixMulp { } // Adding matrices + System.out.println("Result of addition:"); if (m == p && n == q) { - int[][] C = new int[m][n]; + int C[][] = new int[m][n]; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { C[i][j] = A[i][j] + B[i][j]; + System.out.print(C[i][j] + " "); } + System.out.println(); } - System.out.println("Result of addition:"); - printMatrix(C); } // Multiplying matrices + System.out.println("Result of multiplication:"); if (n == p) { - int[][] D = new int[m][q]; + int D[][] = new int[m][q]; for (int i = 0; i < m; i++) { for (int j = 0; j < q; j++) { for (int k = 0; k < n; k++) { D[i][j] += A[i][k] * B[k][j]; } + System.out.print(D[i][j] + " "); } + System.out.println(); } - System.out.println("Result of multiplication:"); - printMatrix(D); } } }