有一对兔子,从出生后第3个月起每个月都生一对兔子,
小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月
的兔子总数为多少? 兔子的规律为数列1,1,2,3,5,8,13,21.... 

解决方案 »

  1.   

    lz的题目显然是斐波那契数列的变种     {  =1  (n<3)
    f(n)={  
         {  =f(n-1)+f(n-3)
    public static int f(int n)
    {
    if(n<3)
    return 1;
    return f(n-1)+f(n-3);
    }测试得到:
    1 1 2 3 4 6 9 13 19 28
      

  2.   

    f(n+1)/f(n)=0.618...    黄金分割
      

  3.   

    redduke1202(勿以分少而不回★★勿以分多而灌水) 我怎么用你的方法,得到的结果却不太对,先谢谢。
      

  4.   

    public class tu {
    public static void main(String args[]){
    int n = 0;
    int max=40;
    int[] a = new int[max];
    for(n=0;n<max;n++){
    if(n<2) a[n]=1;
    else  a[n]=a[n-1]+a[n-2];
    }
    for(n=0;n<max;n++) System.out.println(a[n]);
    }
    }
    偶寫的,不知道符合題意不!!
      

  5.   

    wanguanghai(心灵鸡汤) 、redduke1202(勿以分少而不回★★勿以分多而灌水)、jinancf(单身汉) 、aliwkxqq()、aliwkxqq() 、kingstro() 谢谢大家的解答,CSDN真好!!我的答案:
    public class MyEx1 {
    public static void main(String[] args) {
    MyEx1.f(10);
    }

    public static void f(int number)
    {
        int a0=1,a1=1,loop=0,result=2;
        for(loop=0;loop<=number;loop++){
         result=a0+a1;
         a0=a1;
         a1=result;
         System.out.print(result+" ");
        }
    }
    }