Skip to content

Commit ced4cfb

Browse files
committed
Fix: improve factorial implementation and formatting
1 parent f312cdb commit ced4cfb

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/main/java/com/thealgorithms/maths/Factorial.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ public static BigInteger factorial(int n) {
1616
if (n < 0) {
1717
throw new IllegalArgumentException("Input number cannot be negative");
1818
}
19-
BigInteger factorial = BigInteger.ONE;
20-
for (int i = 1; i <= n; ++i) {
21-
factorial = factorial.multiply(BigInteger.valueOf(i));
19+
BigInteger result = BigInteger.ONE;
20+
for (int i = 1; i <= n; i++) {
21+
result = result.multiply(BigInteger.valueOf(i));
2222
}
23-
return factorial;
23+
return result;
2424
}
2525
}

0 commit comments

Comments
 (0)