题解 | #统计每个月兔子的总数#
import java.util.*; // 注意类名必须为 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 a = in.nextInt(); /** * 斐波那契数列 * 1月 1 2月 1 3月 2 4月 3 5月 5 6月 8 结论:N月=(N-1)月+(N-2)月 */ System.out.println(compute(a)); } } public static int compute(int month){ if(month==1 || month ==2){ return 1; } else{ return compute(month-1)+compute(month-2); } } }