Skip to content

Commit c9f57d0

Browse files
committed
Add necessary comment to MatrixMultiplication.java
1 parent fcfd803 commit c9f57d0

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ private MatrixMultiplication() {
1313
* @throws IllegalArgumentException if the matrices cannot be multiplied
1414
*/
1515
public static double[][] multiply(double[][] matrixA, double[][] matrixB) {
16-
16+
// Check the input matrices are not null
1717
if (matrixA == null || matrixB == null) {
1818
throw new IllegalArgumentException("Input matrices cannot be null");
1919
}
2020

21+
// Validate the matrix dimensions
2122
if (matrixA[0].length != matrixB.length) {
2223
throw new IllegalArgumentException("Matrices cannot be multiplied: incompatible dimensions.");
2324
}
@@ -26,8 +27,10 @@ public static double[][] multiply(double[][] matrixA, double[][] matrixB) {
2627
int colsA = matrixA[0].length;
2728
int colsB = matrixB[0].length;
2829

30+
// Initialize the result matrix with zeros
2931
double[][] result = new double[rowsA][colsB];
3032

33+
// Perform matrix multiplication
3134
for (int i = 0; i < rowsA; i++) {
3235
for (int j = 0; j < colsB; j++) {
3336
for (int k = 0; k < colsA; k++) {

0 commit comments

Comments
 (0)