Search

Thursday, September 17, 2015

How to use BigInteger class in Java? Large Factorial Example

When you calculate factorial of a relatively higher number most of the data type in Java goes out of their limit. For example, you cannot use int or long variable to store factorial of a number greater than 50. In those scenarios where int and long are not big enough to represent an integral value, you can use java.math.BigInteger class. BigInteger variable can represent any integral number, there is no theoretical limit, but it allocates only enough memory required to hold all the bits of data it is asked to hold. There is not many time you need this class but its good to know about it and that's why I am giving one scenario which is perfectly suitable for using BigInteger class. In this article, you will learn how to calculate factorial of large number using BigInteger object. We will use same formula, we have used to calculate normal factorials as discussed in my previous post about factorials.
Read more »

No comments:

Post a Comment