Java Scanner hasNextBigInteger() MethodThe hasNextBigInteger() is a Java Scanner class method which is used to check the next token in this scanner's input can be interpreted as a BigInteger value in the default radix or not. It returns true if it is interprated as a BigInteger value, otherwise returns false. There is two different types of Java hasNextBigInteger() method which can be differentiated depending on its parameter. These are:
hasNextBigInteger() Method:This is a Java Scanner class method which is used to check the next token in this scanner's input can be interpreted as a BigInteger value in the default radix using the nextBigInteger() method. hasNextBigInteger(int radix) Method:This is an inbuilt method of Java Scanner class which is used to check the next token in this scanner's input can be interpreted as a BigInteger value in the specified radix using the nextBigInteger() method. SyntaxFollowing is the declaration of hasNextBigInteger() method: Parameter
ReturnsThe hasNextBigInteger() method returns true if and only if this scanner's next token is a valid Integer value. ExceptionsIllegalStateException- This method throws exception if the innvocation is done after the scanner has been closed. IllegalArgumentException- It throws this exception if the specified radix is out of range. Compatibility VersionJava 1.5 and above Example 1Output: Found Integer Value: 22 Not Found Integer Value: Double Found Integer Value: 75 Not Found Integer Value: number Not Found Integer Value: is Not Found Integer Value: 2123324.58 Example 2Output: Exception in thread "main" java.lang.IllegalArgumentException: radix:598670 at java.base/java.util.Scanner.setRadix(Scanner.java:1368) at java.base/java.util.Scanner.nextBigInteger(Scanner.java:2673) at myPackage.ScannerHasNextBigIntegerExample2.main(ScannerHasNextBigIntegerExample2.java:9) Example 3Output: Not Found :JavaTpoint.com Found :11 Not Found :+ Found :11 Not Found := Not Found :22.0 Example 4Output: Please enter value: 3453740 Your entered value: 3453740 Next TopicJava-scanner-hasnextboolean-method |