intValueExact(): This method is available in java.math.BigInteger class of Java.
Syntax:
int java.math.BigInteger.intValueExact()
This method converts this BigInteger to an int, checking for lost information. If the value of this BigIntegeris out of the range of the int type, then an ArithmeticException is thrown.
Returns: this BigInteger converted to an int.
Throws: ArithmeticException - if the value of this will not exactly fit in an int.
For Example:
BigInteger bigInteger = new BigInteger("1234")
bigInteger.intValueExact() = > It returns 1234.
Approach
Java
import java.math.BigInteger;public class BigIntegerintValueExact {public static void main(String[] args) {BigInteger bigInteger = new BigInteger("1234");System.out.println(bigInteger.intValueExact());}}
Output:
1234
No comments:
Post a Comment