From bb4743a9ed35e3fbe1d9e618b95896e9828d6ff6 Mon Sep 17 00:00:00 2001 From: Aadit Agrawal Date: Sat, 31 Aug 2024 09:27:59 +0530 Subject: [PATCH] Update OOP/Java/Lab/Week4/MatrixMulp.java --- OOP/Java/Lab/Week4/MatrixMulp.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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); } } }