Skip to content

Commit 6d16a54

Browse files
committed
Check for empty matrices part updated
1 parent 64a97db commit 6d16a54

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/main/java/com/thealgorithms/matrix/MatrixMultiplication.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ public static double[][] multiply(double[][] matrixA, double[][] matrixB) {
1818
throw new IllegalArgumentException("Input matrices cannot be null");
1919
}
2020

21+
// Check for empty matrices
22+
if (matrixA.length == 0 || matrixB.length == 0 ||
23+
matrixA[0].length == 0 || matrixB[0].length == 0) {
24+
throw new IllegalArgumentException("Input matrices must not be empty");
25+
}
26+
2127
// Validate the matrix dimensions
2228
if (matrixA[0].length != matrixB.length) {
2329
throw new IllegalArgumentException("Matrices cannot be multiplied: incompatible dimensions.");

0 commit comments

Comments
 (0)