题解 | #统计每个月兔子的总数#
统计每个月兔子的总数
https://www.nowcoder.com/practice/1221ec77125d4370833fd3ad5ba72395
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int child1月 = 1; //第一个月只有一只兔子
int child2月 = 0;
int audlt = 0;
int month = in.nextInt();
for(int i =1;i<month;i++){//第二个月
audlt = audlt+child2月;//第二月兔变成年兔
child2月 = child1月; //第一月兔变第二月兔
child1月 = audlt; //成年兔生了一窝第一月兔
}
System.out.print(child1月+child2月+audlt);
}
}
}
