Java BigInteger calculate factorial
import java.math.BigInteger; public class Main { public static void main(String[] args) { System.out.println("50! is \n" + factorial(50)); }//ww w . j a v a 2s.c o m public static BigInteger factorial(long n) { BigInteger result = BigInteger.ONE; for (int i = 1; i <= n; i++) result = result.multiply(new BigInteger(i + "")); return result; } }