How to calculate Large Factorials using BigInteger in Java?
Important things about BigInteger class in Java
BigInteger class in Java is designed to deal with really large numbers in Java, but to do that its very important that you make yourself familiar with class. Here are some key points about java.math.BigInteger class :1. The BigInteger class is used to represent arbitrarily large numbers. Overflow doesn't occur as is the case with int and long primitive.
2. The BigInteger class is immutable which means that the object on which the multiply function was invoked doesn't change the integer it is holding. The multiplication is performed and a new BigInteger is returned which needs to be stored in the variable fact.
3. BigInteger provides operations similar to int primitive type in Java, additionally it provide support for prime generation, bit manipulation, GCD calculations etc.
4. You can create BigInteger object by giving number as String or byte array using constructor, or you can convert a long value to BigInteger using valueOf() method as shown below :
Read full article from How to calculate Large Factorials using BigInteger in Java?
No comments:
Post a Comment