提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
大整数递归fibonacci方法
import java.math.BigInteger;/** from NowJava.com**/ public class Main { private static BigInteger TWO = BigInteger.valueOf(2); // recursive declaration of method fibonacci public static BigInteger fibonacci(BigInteger number) { if (number.equals(BigInteger.ZERO) || number.equals(BigInteger.ONE)) // base cases return number; else { return fibonacci(number.subtract(BigInteger.ONE)).add(fibonacci(number.subtract(TWO))); } } // displays the fibonacci values from 0-40 public static void main(String[] args) {//来 自 时代Java - nowjava.com for (