1 【程序 1 1 不死神兔 】
题目:古典问题:有一对兔子,从出生后第 3 个月起每个月都生一对兔子,小兔子长到第三个月后每个月
又生一对兔子,假如兔子都不死,问每个月的兔子对数为多少?
程序分析: 兔子的规律为数列 1,1,2,3,5,8,13,21…
package 王道作业;
/*
* 程序1 不死神兔
* 分析:斐波那契数列
*
*/
public class Pro01_Rabit {
static long[] num = new long[50];
public static void main(String[] args) {
numOfRabit();
for(int i=0; i<50; i++) {
System.out.print(num[i]+"\t");
}
}
public static void numOfRabit() {
num[0] = 1;
num[1] = 1;
for(int i=2; i<50; i++) {
num[i] = num[i-2] + num[i-1];
}
}
}