BigInteger class
In this chapter you will learn:
BigInteger
BigInteger
is an immutable class that represents a signed
integer of arbitrary precision.
BigInteger
declares three convenience constants: ONE, TEN,
and ZERO. Each constant is the
BigInteger equivalent of 1, 10, and 0.
import java.math.BigInteger;
/*from ja v a 2 s .co m*/
public class Main {
public static void main(String[] args) {
BigInteger numberB = BigInteger.TEN;
}
}
Compare with BigInteger constant value
We can compare BigInteger value against the constant value.
import java.math.BigInteger;
/*from j av a 2s . com*/
public class Main {
public static void main(String[] args) {
System.out.println(factorial(new BigInteger("170")));
}
static BigInteger factorial(BigInteger n) {
if (n.equals(BigInteger.ZERO))
return BigInteger.ONE;
else
return n.multiply(factorial(n.subtract(BigInteger.ONE)));
}
}
Next chapter...
What you will learn in the next chapter:
- How to create BigInteger from byte array
- How to create BigInteger from String
- How to use different radix to create BigInteger from String
- How to create BigInteger with random number
Home » Java Tutorial » BigDecimal BigInteger