1. 程式人生 > >斐波那契數列問題(遞歸問題)

斐波那契數列問題(遞歸問題)

斐波那契數列 shu static summer code int com pack 使用遞歸

package com.Summer_0419.cn;

/**
 * @author Summer
 * 一列數的規則如下: 1、1、2、3、5、8、13、21、34 .....
 * 求第30位數是多少?
 * 使用遞歸實現
 *
 */
public class Test_Method08 {

    public static void main(String[] args) {
        int num = count(30);
        System.out.println(num);
    }

    private static int
count(int weishu) { if (weishu==1||weishu==2) { return 1; } return count(weishu-1)+count(weishu-2); } }

斐波那契數列問題(遞歸問題)