Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/main/java/com/thealgorithms/recursion/FibonacciSeries.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
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 ...
*/
/**
* The Fibonacci series is a sequence of numbers where each number is the sum of the two preceding ones,
* starting with 0 and 1.
* <p>
* Example:
* 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 ...
* </p>
*/

public final class FibonacciSeries {
private FibonacciSeries() {
throw new UnsupportedOperationException("Utility class");
}

/**
* Calculates the nth term in the Fibonacci sequence using recursion.
*
* @param n the position in the Fibonacci sequence (must be non-negative)
* @return the nth Fibonacci number
* @throws IllegalArgumentException if n is negative
*/
public static int fibonacci(int n) {
if (n < 0) {
throw new IllegalArgumentException("n must be a non-negative integer");
Expand Down