mirror of
https://github.com/TheAlgorithms/Java.git
synced 2026-03-13 08:40:43 +08:00
docs: add Javadoc to FibonacciSeries (#7215)
* docs: add Javadoc to FibonacciSeries * fix: make small adjustment --------- Co-authored-by: Deniz Altunkapan <deniz.altunkapan@outlook.com>
This commit is contained in:
@@ -1,16 +1,26 @@
|
|||||||
package com.thealgorithms.recursion;
|
package com.thealgorithms.recursion;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
The Fibonacci series is a sequence of numbers where each number is the sum of the two preceding ones,
|
* The Fibonacci series is a sequence of numbers where each number is the sum of the two preceding ones,
|
||||||
starting with 0 and 1.
|
* starting with 0 and 1.
|
||||||
NUMBER 0 1 2 3 4 5 6 7 8 9 10 ...
|
* <p>
|
||||||
FIBONACCI 0 1 1 2 3 5 8 13 21 34 55 ...
|
* Example:
|
||||||
*/
|
* 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 ...
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
|
||||||
public final class FibonacciSeries {
|
public final class FibonacciSeries {
|
||||||
private FibonacciSeries() {
|
private FibonacciSeries() {
|
||||||
throw new UnsupportedOperationException("Utility class");
|
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) {
|
public static int fibonacci(int n) {
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
throw new IllegalArgumentException("n must be a non-negative integer");
|
throw new IllegalArgumentException("n must be a non-negative integer");
|
||||||
|
|||||||
Reference in New Issue
Block a user