Factorial of Large Number in Java

It is beyond the realm of imagination to expect to store factorial for a huge number like 50 into inbuilt information types like a whole number or long.

Since factorial of 50 has just about 60 digits. Envision how we can store it in int or long.

We can discover factorial of such numbers utilizing BigInteger class characterized in java. math bundle.

Beneath program shows how you can do this.


import java.math.BigInteger;
import java.util.Scanner;
class BigFactorial {
	public static void main(String arg[]){
		BigInteger fac=new BigInteger("1");
		int n;
		Scanner sc=new Scanner(System.in);
		System.out.println("Enter a number:");
		for(int i=2;i<=n;++i){


Factorial of Large Number in Java

Leave a Comment

error: Alert: Content is protected!!