Javatpoint Logo
Javatpoint Logo

Java Scanner nextDouble() Method

The nextDouble() is a method of Java Scanner class which is used to scan the next token of the input as a double. If the translation is successful, the scanner past the input that matched.


Following is the declaration of nextDouble() method:


This method does not accept any parameter.


The nextDouble() method returns the double scanned from the input.


InputMismatchException- It will thrown this Exception if the next token does not match the Float regular expression, or is out of range.

NoSuchElementException- It will thrown this Exception if the input is exhausted.

IllegalStateException- It will thrown this Exception if the innvocation is done after Scanner is closed.

Compatibility Version

Java 1.5 and above

Example 1


Enter the amount: 
Enter the Total Balance: 
Left Balance is: 5470832.356

Example 2


Not Found Double:Hello
Not Found Double:World!
Found Double:12.0
Not Found Double:+
Found Double:13.0
Not Found Double:=
Found Double:15.0
Not Found Double:2.123

Example 3


Enter value: 375437.565
Your entered Double value: 375437.565

Example 4


Enter the numeric value : 12345
Double value : 12345.0 
Twice value : 24690.0
Next TopicJava Scanner Class

Help Others, Please Share

facebook twitter pinterest