Javatpoint Logo
Javatpoint Logo

Java Scanner nextBigDecimal() Method

The nextBigDecimal() is a method of Java Scanner class which scan the next token of the input as a BigDecimal.

Syntax

Following is the declaration of nextBigDecimal() method:

Parameter

This method does not accept any parameter.

Returns

The nextBigDecimal() method returns the BigDecimal scanned from the input.

Exceptions

IllegalStateException- This method throws exception if the innvocation is done after the scanner has been closed.

InputMismatchException- It will thrown exception if the next token does not match the Decimal regular expression or is out of range

Compatibility Version

Java 1.5 and above

Example 1

Output:

Enter the two decimal inputs-
123456789
987654321
Result is: 1111111110

Example 2

Output:

Exception in thread "main" java.util.InputMismatchException
	at java.base/java.util.Scanner.throwFor(Scanner.java:939)
	at java.base/java.util.Scanner.next(Scanner.java:1594)
	at java.base/java.util.Scanner.nextBigDecimal(Scanner.java:2742)
	at myPackage.ScannerNextBigDecimalExample2.main(ScannerNextBigDecimalExample2.java:7)

Example 3

Output:

Not Found :Google.com
Found :111
Not Found :+
Found :11111
Not Found :=
Found :11222.0
Not Found :true
Next TopicJava Scanner Class


Help Others, Please Share

facebook twitter pinterest