package com.oneProject;
import java.util.Scanner;
/*
题目:
有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子对数为多少?
思路:
1、兔子的规律 1 1 2 3 5 8 13 31 34 55
2、使用递归算法
*/
public class Rabbit {
public static void main(String[] args) {
Scanner ss=new Scanner(System.in);
System.out.println(“输入月数”);
int a =ss.nextInt();
for (int i=1;i<=a;i++) {
System.out.println(“第”+a +“月的数为”+fun(a));
break;
}
}
private static int fun(int n) {
if (n == 1 || n == 2)
return 1;
else
return fun(n - 1) + fun(n - 2);
}
}