Here you can find the source of fibonacci(int n)
Parameter | Description |
---|---|
size | Required length of the sequence |
public static int fibonacci(int n)
//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); } } }