Fibonacci数列
费波那契数列由0和1开始,之后的费波那契系数就是由之前的两数相加而得出
![](https://gss1.bdstatic.com/9vo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D48/sign=a9d741be02f79052eb1f46360df3ed45/e1fe9925bc315c60bddb594286b1cb13485477d4.jpg)
![](https://gss2.bdstatic.com/-fo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D48/sign=53b2e240ec1190ef05fb93d7cf1b2059/9f510fb30f2442a70fb4cf08da43ad4bd01302e0.jpg)
![](https://gss0.bdstatic.com/94o3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D162/sign=7682af4ef61f4134e4370178171e95c1/aa18972bd40735fa36517c1495510fb30e2408fd.jpg)
0,1,1,2,3,5,8,13,21,34,55,89,144,233
package com.wolaidai.finance.loan.service.confirm.impl; /** * f(0) = 0; * f(1) = 1; * f(2) = 1; * f(3) = 2; * * 0, 1, 1, 2, 3, 5, 8, * <img src=""></img> * @author rong.e * */ public class T { public static void main(String[] args) { new T().test(); } public void test() { // f(n) = ? int r = fibonacci(6, 1, 1); System.err.println(r); } public int fibonacci(int n, int a, int b) { if (n < 0) { return -1; } else if (n == 1 || n == 2) { return b; } else { while (n > 2) { return fibonacci(n - 1, b, b + a); } } return 0; } }