当前位置: 代码迷 >> 综合 >> 使用斐波那契数兔子
  详细解决方案

使用斐波那契数兔子

热度:35   发布时间:2024-01-25 10:31:51.0
package com.example.demo.contorller;public class test1 {public static void main(String[] args) {//f(n) = f(n - 1) + f(n - 2)斐波那契约//有一对兔子,第三个月就能生一对兔子,以后每个月这一对兔子都生一对兔子;新出生的兔子第三个月也能开始生兔子,也是之后每个月都生一对兔子math ma=new math();for (int i=1;i<=30;i++){System.out.println(math.fmath(i));}}
}
class math{public static int fmath(int x){if (x==1||x==2){return 1;}else{return fmath(x-1)+fmath(x-2);}}
}
  相关解决方案