java.math.BigInteger.byteValueExact() is an inbuilt function added in Java SE 9 & JDK 9 which returns BigInteger value of square root of a BigInteger on which sqrt() methhod is applied. It is same as the floor(sqrt(n)) where n is a number.This Square root is less than real square root if the real square root can not representable as an integral value.
public BigInteger sqrt()
Parameters: The method does not take any parameters.
Return Value: Method returns the integer square root of this BigInteger.
Exception: The method will throw ArithmeticException if BigInteger is negative.
Input: 234876543456 Output: 484640 Explanation: 122 is given as input which is the bigInteger. The square root of 122 is 11.04536 whose BigInteger equivalent is 11 and using sqrt() method of BigInteger class we can get Square root of any BigInteger. Input: 122 Output: 11
Below programs illustrates sqrt() method of BigInteger class:
Program 1: Showing application of sqrt() method to get square root of 31739.
Square root value of BigInteger 31739 is 178
Program 2: Showing Exception thrown by sqrt() method.
java.lang.ArithmeticException: Negative BigInteger at java.base/java.math.BigInteger.sqrt(Unknown Source) at GFG.main(GFG.java:19) Square root value of BigInteger -2345 is null
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- StrictMath sqrt() Method in Java
- Java sqrt() method with Examples
- BigDecimal sqrt() Method in Java with Examples
- BigInteger not() Method in Java
- BigInteger and() Method in Java
- BigInteger pow() Method in Java
- BigInteger mod() Method in Java
- BigInteger or() method in Java
- BigInteger xor() Method in Java
- BigInteger abs() Method in Java
- Java.math.BigInteger.probablePrime() method in Java
- Java.math.BigInteger.modInverse() method in Java
- BigInteger remainder() Method in Java
- BigInteger valueOf() Method in Java
- BigInteger toByteArray() Method in Java
- BigInteger gcd() Method in Java with Examples
- BigInteger add() Method in Java with Examples
- BigInteger bitCount() Method in Java
- BigInteger bitLength() Method in Java
- BigInteger clearBit() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : shubham_singh