统计每个月兔子的总数
统计每个月兔子的总数
http://www.nowcoder.com/questionTerminal/1221ec77125d4370833fd3ad5ba72395
import java.util.Scanner;
public class Main {
private int getTotalCount(int n) {
int[] f = new int[n + 1];
f[0] = 0;
f[1] = 1;
for (int i = 2; i <= n; i++) {
f[i] = f[i-2] + f[i-1];
}
return f[n];
}
public Main() {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) {
int monthCount = in.nextInt();
int result = getTotalCount(monthCount);
System.out.println(result);
}
}
public static void main(String[] args) {
Main solution = new Main();
}
}