Output Fibonacci Series in Java

Published: March 19, 2019

1, 1, 2, 3, 5, 8, 13, 21...

Here's an example of a function that takes in the index of the number in the Fibonacci series, and returns the number.

private static void fibonacci(int n){
    if(n <= 1)
        return n;
    return fibonacci(n - 1) + fibonacci(n - 2);
}

The outout of this will be:

fibonacci(6); //8


Share this article