Java Utililty Methods BigInteger Factorial

List of utility methods to do BigInteger Factorial

Description

The list of methods to do BigInteger Factorial are organized into topic(s).

Method

BigIntegerfactorial(BigInteger n)
Naive (dumb) implementation of the factorial function.
if (n.equals(BigInteger.ONE)) {
    return BigInteger.ONE;
return n.multiply(factorial(n.subtract(BigInteger.ONE)));
BigIntegerfactorial(BigInteger n)
Compute the Factorial of n, often written as c! in mathematics.
BigInteger nFac = BigInteger.ONE;
while (n.compareTo(BigInteger.ONE) > 0) {
    nFac = nFac.multiply(n);
    n = n.subtract(BigInteger.ONE);
return nFac;
BigIntegerfactorial(BigInteger number)
factorial
BigInteger result = BigInteger.valueOf(1);
for (long factor = 2; factor <= number.longValue(); factor++) {
    result = result.multiply(BigInteger.valueOf(factor));
return result;
BigIntegerfactorial(BigInteger originValue)
factorial
BigInteger one = new BigInteger("1");
BigInteger result = new BigInteger("1");
while (originValue.compareTo(one) > 0) {
    result = result.multiply(originValue);
    originValue = originValue.subtract(one);
return result;