Java Fibonacci Sequence Get fibonacci(int n)

Here you can find the source of fibonacci(int n)

Description

Generates a fibonacci series of specified length and returns it as a list of integers to the caller

License

Open Source License

Parameter

Parameter Description
size Required length of the sequence

Return

The next number in the sequence

Declaration

public static int fibonacci(int n) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//w  w  w.  j  av a  2s  . c o  m
     * Generates a fibonacci series of specified length and
     * returns it as a list of integers to the caller
     * @param size Required length of the sequence
     * @return The next number in the sequence
     */
    public static int fibonacci(int n) {
        if (n == 0) {
            return 0;
        } else if (n == 1) {
            return 1;
        } else {
            return fibonacci(n - 1) + fibonacci(n - 2);
        }
    }
}

Related

  1. esFibo(long value)
  2. fib(int n)
  3. fiboCercano(long numero)
  4. fibonacci(int n)
  5. fibonacci(int n)
  6. fibonacci(long max)
  7. getFibonacci(int number)
  8. getFibonacciSeq(long f)