题解 | #统计每个月兔子的总数#
统计每个月兔子的总数
https://www.nowcoder.com/practice/1221ec77125d4370833fd3ad5ba72395
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int sum = Integer.parseInt(scanner.nextLine());
List<Integer> lists = new ArrayList<>();
lists.add(1);
lists.add(1);
if (sum <= 2) {
System.out.println("1");
return;
} else {
for (int i = 2; i < sum; i++) {
lists.add(i, lists.get(i - 2) + lists.get(i - 1));
}
System.out.println(String.valueOf(lists.get(lists.size() - 1)));
}
}
}
查看11道真题和解析