有一对兔子,从出生后第三个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数是多少
/**
* 斐波那契数列
* 有一对兔子,从出生后第三个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子
* 假如兔子都不死,问每个月的兔子总数是多少
* @author 努力Coding
* @version
* @data
*/
public class Fibonacci {
public static void main(String[] args) {
int[] nums = new int[10];//声明一个数组
nums[0] = nums[1] = 1;//前两个月兔子数量为1
/*从第三个月起,每个月的兔子数其实等于前两个月兔子数的和*/
for(int i = 2; i < nums.length; i++) {
nums[i] = nums[i - 1] + nums[i - 2];
System.out.println("第" + (i + 1) + "个月的兔子数量为:" + nums[i]);
}
}
}
原文:https://www.cnblogs.com/Zhouge6/p/12158074.html