Add Fibonacci series to Recursion package (#6079)

This commit is contained in:
Mohamed Boukthir
2024-11-02 21:44:24 +01:00
committed by GitHub
parent df0c997e4b
commit 539871a33e
2 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,21 @@
package com.thealgorithms.Recursion;
/*
The Fibonacci series is a sequence of numbers where each number is the sum of the two preceding ones,
starting with 0 and 1.
NUMBER 0 1 2 3 4 5 6 7 8 9 10 ...
FIBONACCI 0 1 1 2 3 5 8 13 21 34 55 ...
*/
public final class FibonacciSeries {
private FibonacciSeries() {
throw new UnsupportedOperationException("Utility class");
}
public static int fibonacci(int n) {
if (n <= 1) {
return n;
} else {
return fibonacci(n - 1) + fibonacci(n - 2);
}
}
}