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.

Syntax

Following is the declaration of nextDouble() method:

Parameter

This method does not accept any parameter.

Returns

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

Exceptions

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

Output:

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

Example 2

Output:

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

Output:

Enter value: 375437.565
Your entered Double value: 375437.565

Example 4

Output:

Enter the numeric value : 12345
Double value : 12345.0 
Twice value : 24690.0