提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
创建递归方法来计算斐波那契
import java.math.BigInteger; public class Main/* 来自 n o w j a v a . c o m - 时代Java*/ { 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 // recursion step return fibonacci(number.subtract(BigInteger.ONE)).add( fibonacci(number.subtract(TWO))); } /*时代Java公众号*/ // displays the fibonacci values from 0-40 public static void main(String[] args) { for (