package test;
public class RabbitReproduction_mlj {
/*
兔子繁殖 有一对兔子 从出生后第三个月起每个月都生一对兔子 小兔子长到第三个月后又生一对兔子
假如兔子都不死 问第二十个月的兔子对数为多少
思路 1 1 2 3 5 8 13......菲波那切数列
a b
a b pre
a b next
求b.next
b.next=a.pre+b.pre
b.next=a.pre+a.next
*/
public static void main(String [] args) {
int i;
int a=1,b=1,temp;
for (i = 1; i <= 8; i++) {
//i<=18 因为第一个月和第二个月 兔子不生孩子
temp = a;
a = b;
b = temp + a;
}
System.out.println(b);
}
}
兔子繁殖
最新推荐文章于 2021-01-11 00:03:12 发布