提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
大整数的递归阶乘方法。
import java.math.BigInteger; public class Main/**时 代 J a v a 公 众 号 - nowjava.com**/ { // recursive method factorial (assumes its parameter is >= 0) public static BigInteger factorial(BigInteger number) { if (number.compareTo(BigInteger.ONE) <= 0) // test base case return BigInteger.ONE; else // recursion step return number.multiply(factorial(number.subtract(BigInteger.ONE))); } // output factorials for values 0-50 public static void main(String[] args) {// from 时 代 J a v a - nowjava.com // calculate the factorials of 0 through 50 for (