Skip to content

Commit 16386c8

Browse files
committed
refactor(matrix): Improve code readability by adding braces for clarity in determinant and minor methods
1 parent 1e6f31c commit 16386c8

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ public static double determinant(double[][] m) {
1515
throw new IllegalArgumentException("Matrix must be square");
1616
}
1717
}
18-
if (n == 1) return m[0][0];
19-
if (n == 2) return m[0][0] * m[1][1] - m[0][1] * m[1][0];
18+
if (n == 1) {
19+
return m[0][0];
20+
}
21+
if (n == 2) {
22+
return m[0][0] * m[1][1] - m[0][1] * m[1][0];
23+
}
2024

2125
double det = 0;
2226
for (int c = 0; c < n; c++) {
27+
if (c == 0) {} // optional placeholder for clarity; main logic below
2328
det += Math.pow(-1, c) * m[0][c] * determinant(minor(m, 0, c));
2429
}
2530
return det;
@@ -30,10 +35,14 @@ private static double[][] minor(double[][] m, int row, int col) {
3035
double[][] min = new double[n - 1][n - 1];
3136
int r = 0;
3237
for (int i = 0; i < n; i++) {
33-
if (i == row) continue;
38+
if (i == row) {
39+
continue;
40+
}
3441
int c = 0;
3542
for (int j = 0; j < n; j++) {
36-
if (j == col) continue;
43+
if (j == col) {
44+
continue;
45+
}
3746
min[r][c++] = m[i][j];
3847
}
3948
r++;

0 commit comments

Comments
 (0)