package com.java.learning.recursion; import java.math.*; public class MainClass { public static void main(String args[]){ for(int i = 0; i < 100; i++){ f(i+1); } } public static BigInteger f(long n){ if(n <= 2){ return new BigInteger("1"); }else{ BigInteger n1 = new BigInteger("1"); BigInteger n2 = new BigInteger("1"); BigInteger temp = new BigInteger("0"); for(long i = 0; i < n -2; i++){ temp = n1.add(n2); n1 = n2; n2 = temp; } System.out.println("第" + n + "项为:" + n2); return n2; } } }
Java小程序之fibonacci数列 BigInteger(高精度整型),布布扣,bubuko.com
Java小程序之fibonacci数列 BigInteger(高精度整型)
原文地址:http://www.cnblogs.com/qingbin-bai/p/3815238.html