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);
}
}
}
来源:CSDN
作者:优秀是一种信仰
链接:https://blog.csdn.net/weixin_40593587/article/details/104016022