2

JZ-007-斐波那契数列

 2 years ago
source link: https://segmentfault.com/a/1190000040870607
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

JZ-007-斐波那契数列

发布于 10 月 27 日

斐波那契数列

大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0,第1项是1)。

  • n<=39

题目链接: 斐波那契数列

public class Jz07 {

    /**
     * 递归
     *
     * @param n
     * @return
     */
    public static int fibonacci(int n) {
        if (n == 0 || n == 1) {
            return n;
        }
        return fibonacci(n - 1) + fibonacci(n - 2);
    }

    public static void main(String[] args) {
        System.out.println(fibonacci(4));
    }
}

【每日寄语】 不要停止奔跑,值得期待的只有前方。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK