Skip to content

Instantly share code, notes, and snippets.

package example;
import java.math.BigInteger;
public class Factorial {
public static BigInteger factorial(final int n) {
BigInteger res = BigInteger.valueOf(1L); //build upresult
for (int i = n; i > 1; i--)
res = res.multiply(BigInteger.valueOf(i));
return res;