斐波拉契数列 注意:第零项是0,第一项是第一个1。 第0项是0,从第三项开始,每一项都等于前两项的和。
package com.etime.test019; public class Test16 { public static void main(String[] args) { int i = test1(6); System.out.println(i); } public static int test1(int n) { if(n==0) { return 0; }else if(n==1) { return 1; }else if(n>1){ return test1(n-1)+test1(n-2); }else { System.out.println("数据有误!"); return -1; } } }
下面为运行效果图
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2018 群英 版权所有 茂名市群英网络有限公司
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号-36 粤公网安备 44090202000006号 粤工商备P091701000595