青蛙跳台阶(递归算法)

题目:青蛙跳台阶算法,每次可以跳1级或两级,请问有n级台阶,有多少种算法

 

package bianchengti;
/*
 * 青蛙跳台阶算法
 * 每次可以跳1级或两级,请问有n级台阶,有多少种算法
 * 递归算法
 */
public class FrogJump {
    public static int JumpFloor(int n) {
        if(n<0)
            return 0;
        int []fibArry = {0,1,2};
        if(n<3)
            return fibArry[n];
        return JumpFloor(n-1)+JumpFloor(n-2);
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println(JumpFloor(5));//8
    }

}

 

posted @ 2017-09-23 13:13  刘镇平Jasper  阅读(855)  评论(0编辑  收藏  举报