package AlgorithmTest; /** * Created by dell on 2015/10/5. */ public class FabonacciCircleImplementTest { public static void main(String[] args) { System.out.println(FabonacciCircleImplement.fabonacci(4)); System.out.println(FabonacciCircleImplement.fabonacci(5)); } } class FabonacciCircleImplement{ public static long fabonacci(final int n){ if (n == 0){ return 0; } if (n == 1){ return 1; } long currentNum = 1; long preNum = 0; for (int i = 0; i < n - 1; ++i){ long temp = currentNum; currentNum = currentNum + preNum; preNum = temp; } return currentNum; } }
斐波那契数列的非递归实现 JAVA
最新推荐文章于 2022-01-15 23:16:02 发布