We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7d51c7f commit 48e02b3Copy full SHA for 48e02b3
src/main/java/com/thealgorithms/recursion/FibonacciSeries.java
@@ -12,10 +12,12 @@ private FibonacciSeries() {
12
throw new UnsupportedOperationException("Utility class");
13
}
14
public static int fibonacci(int n) {
15
+ if (n < 0) {
16
+ throw new IllegalArgumentException("n must be a non-negative integer");
17
+ }
18
if (n <= 1) {
19
return n;
- } else {
- return fibonacci(n - 1) + fibonacci(n - 2);
20
21
+ return fibonacci(n - 1) + fibonacci(n - 2);
22
23
0 commit comments