It is not possible to store factorial for large number like 50 into inbuilt data types like integer or long. Because factorial of 50 has almost 60 digits. Imagine how we can store it in int or long. We can find factorial of such numbers using **BigInteger** class defined in **java.math** package.

Below program shows how you can do this.

**Also Read: Factorial of Large Number in C and C++**

## Program for Factorial of Large Number in Java

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
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:"); n=sc.nextInt(); for(int i=2;i<=n;++i){ fac=fac.multiply(BigInteger.valueOf(i)); } System.out.println(fac); } } |

**Output**

Comment below if you are facing any difficulty to understand this program.

Why have you used 1 in in the line 6

where

BigInteger fac = new bigInteger(“1”)

Please explain

I have initialized fac with factorial of 1 i.e. 1

I WANT TO KNOW MEANING OF 6%=15 ..C

CAN YOU HELP ME ….

N YOUR POSTS ARE VERY HELPFULL…..

it is 6=6%15;