package com.itheima.lambda;
public class FibonacciRecursion {
public static void main(String[] args) {
//求解2:
//递归的方式去完成
//1.递归的出口
//2.找到递归的规律
//Fn(12) = Fn(11) + Fn(10);
//Fn(11) = Fn(10) + Fn(9);|
//Fn(10) = Fn(9) + Fn(8);
//...
//Fn(3) = Fn(1) + Fn(2);
//Fn(2) = 1;
//Fn(1) = 1;
System.out.println(fib(12));
}
public static int fib(int number){
if(number==1||number==2){
return 1;
}
return fib(number-1)+fib(number-2);
}
}
Java斐波那契数列递归
最新推荐文章于 2024-09-10 16:56:06 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)