Update OOP/Java/Lab/Week4/MatrixMulp.java

This commit is contained in:
Aadit Agrawal 2024-08-31 09:27:59 +05:30
parent 5e9f347b32
commit bb4743a9ed

View File

@ -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);
}
}
}