Skip to content

Commit d616361

Browse files
Fix: add private constructor to Factorial utility class
1 parent 96b80c6 commit d616361

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
package com.thealgorithms.recursion;
22

33
/**
4-
* This class provides a recursive implementation of the factorial function.
4+
* Implementation of factorial using recursion.
5+
* <p>
6+
* The factorial of a non-negative integer n is defined as:
7+
* n! = n × (n-1) × (n-2) × ... × 1, with 0! = 1.
58
*/
6-
public class Factorial {
9+
public final class Factorial {
10+
11+
// Private constructor to prevent instantiation
12+
private Factorial() {
13+
throw new UnsupportedOperationException("Utility class");
14+
}
715

816
/**
9-
* Recursive method to calculate factorial.
17+
* Calculates factorial recursively.
1018
*
11-
* @param n the number to find factorial of
19+
* @param n non-negative integer
1220
* @return factorial of n
1321
* @throws IllegalArgumentException if n is negative
1422
*/

0 commit comments

Comments
 (0)