赞
踩
- /**
- * 一列数的规则如下: 1、1、2、3、5、8、13、21、34...... 求第30位数是多少, 用递归算法实现
- *
- */
- public class Test {
-
- public static void main(String[] args) {
- System.out.println("结果是:"+Test.foo(30));
- }
-
- /**
- * 递归算法实现
- */
- public static int foo(int i){
- if(i<=0)
- return 0;
- else if(i>0 && i<=2)
- return 1;
- return foo(i-1) + foo(i-2);
- }
- }

结果是:832040
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。