题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第四个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少

题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第四个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少


程序分析: 兔子的规律为数列1,1,2,3,5,8,13,21…

public class exp1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int i=0;
for(i=1;i<=20;i++) {
System.out.println(t(i));
}
}
public static int t(int x) {
if(x1||x2)
return 1;
else
return t(x-1)+t(x-2);
}
}

发布了3 篇原创文章 · 获赞 0 · 访问量 2

猜你喜欢

转载自blog.csdn.net/qq_38776359/article/details/105491544
今日推荐