题解 | #统计每个月兔子的总数#

统计每个月兔子的总数

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


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int month = sc.nextInt();
            int sum = total(month);
            System.out.println(sum);
        }
    }

    public static int total(int month) {
        if (month <= 2) {
            return 1;
        } else {
            return total(month - 2) + total(month - 1);
        }
    }
}
全部评论

相关推荐

06-28 22:48
已编辑
广东金融学院 Java
小浪_Coding:学院本+这俩项目不是buff叠满了嘛
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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