Java - BigInteger Class Example Program

Is there any  variable in any programming language to store 100! ?
My answer is NO , So how can we achieve it ?

There are several tricks to do it In  ‘C’  it can be done using simple logic.
Here is  a sample program to find out factorial number without overflow.
The logic behind the program is count the factorial number then split it into smaller pieces and store it into an array at last print the array from reverse order.


// program – 01 




But sometimes its very disturbing to write such kind of code  Don’t worry there is a simple solution in java, use” BigInteger”  class and calculate manipulate any number without Overflow.
Here is a simple program of using “BigInteger” Class.


// program – 02 




But there is some problem of BigInteger class , It is slower, take memory space higher than other operations. Another important aspect of BigInteger class is that it is immutable. This means that you cannot change the stored value of a BigInteger object, instead you need to assign the changed value to a new variable.

Here is a simple to calculate Factorial number.


// Program – 03  



Download PDF