斐波那契数列 发表于 2016-08-04 | 分类于 基础 | 123456789101112131415161718192021222324252627package com.hundsun.netease;/** * Created by zeewane on 2016/8/4/0004. */public class FibonacciDemo { public static void main(String[] args) { System.out.println(Fibonacci(39)); } public static int Fibonacci(int n) { int preNum = 1; int prePreNum = 0; int result = 0; if (n == 0) return 0; if (n == 1) return 1; for (int i = 2; i <= n; i++) { result = preNum + prePreNum; prePreNum = preNum; preNum = result; } return result; }} 用循环的方法去解决,不要用递归。