即为佛波纳契数列。
图片截取至: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) ;
}
}
京公网安备 11010502036488号