Javatpoint Logo
Javatpoint Logo

Java Scanner nextBigInteger() Method

The nextBigInteger() of Java Scanner class method is used to scan the next token of the input as a BigInteger. There is two different types of Java nextBigInteger() method which can be differentiated depending on its parameter. These are:

  • Java Scanner nextBigInteger() Method
  • Java Scanner nextBigInteger(int radix) Method

nextBigInteger() Method

This is a Java Scanner class method which is used to scan the next token of the input as a BigInteger in the default radix.

nextBigInteger(int radix) Method

This is an inbuilt method of Java Scanner class which is used to scan the next token of the input as a BigInteger in the specified radix.

Syntax

Following is the declaration of nextBigInteger() method:

Parameter

DataType Parameter Description Required/Optional
int radix It is used to interpret the token as a BigInteger value. Required

Returns

The nextBigInteger() method returns the BigInteger value scanned from the input.

Exceptions

IllegalStateException- 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.

InputMismatchException- It throws this exception if the next token does not match the Integer regular expression, or is out of range.

Compatibility Version

Java 1.5 and above

Example 1

Output:

Enter BigInteger Number to check prime: 37427347
prime

Example 2

Output:

Enter Value of a: 123456
Enter Value of b: 123456
Result: 15241383936

Example 3

Output:

Found: 55454
Not Found: JavaTpoint
Found: 1
Not Found: +
Found: 1
Not Found: =
Not Found: 2.0
Not Found: False
Not Found: -7987AB

Example 4

Output:

Output: 85

Example 5

Output:

Not Found : Java
Exception in thread "main" java.lang.IllegalArgumentException: radix:81
	at java.base/java.util.Scanner.setRadix(Scanner.java:1368)
	at java.base/java.util.Scanner.nextBigInteger(Scanner.java:2673)
	at myPackage.ScannerNextBigIntegerExample5.main(ScannerNextBigIntegerExample5.java:11)
Next TopicJava Scanner Class


Help Others, Please Share

facebook twitter pinterest