Update OOP/Java/Lab/Week4/MatrixMulp.java
This commit is contained in:
parent
5e9f347b32
commit
bb4743a9ed
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user