题解 | #统计每个月兔子的总数#--兔子数等于前两月之和

统计每个月兔子的总数

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

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int month = in.nextInt();
        int[] arr = new int[month];
        arr[0] = 1;
        arr[1] = 1;
        // 从第三个月起每个月的兔子数等于前两个月兔子数之和
        for (int i = 2; i < month; i++) {
            arr[i] = arr[i - 1] + arr[i - 2];
        }
        System.out.println(arr[month - 1]);
    }
}

全部评论

相关推荐

allin实习的大白...:我把第二个项目发出来了,如果感兴趣可以去研究研究,欢迎交流。 https://gitee.com/jtyjtyjty333/ind-dist-ai-sec-edge-cloud https://github.com/jtylab/ind-dist-ai-sec-edge-cloud
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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