java题解
统计每个月兔子的总数
http://www.nowcoder.com/questionTerminal/1221ec77125d4370833fd3ad5ba72395
即为佛波纳契数列。
图片截取至:https://blog.csdn.net/weixin_35878700/article/details/80542024
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
System.out.println(getTotalCount(n));
}
}
public static int getTotalCount(int monthCount)
{
if(monthCount < 3){
return 1;
}
return getTotalCount(monthCount - 2) + getTotalCount(monthCount - 1) ;
}
}

查看10道真题和解析