java

统计每个月兔子的总数

http://www.nowcoder.com/questionTerminal/1221ec77125d4370833fd3ad5ba72395

import java.util.*;
public class Main{
    public static void main(String[] arg){
        Scanner s=new Scanner(System.in);
        while(s.hasNextInt()){
        int month=s.nextInt();
        System.out.println(count(month));
        }
    }

    private static int count(int month){
        if(month==1||month==2){
            return 1;
        }
        return count(month-1)+count(month-2);
    }
}
全部评论

相关推荐

07-23 11:23
门头沟学院 Java
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-24 13:40
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务