Javatpoint Logo
Javatpoint Logo

Java Scanner hasNextDouble() Method

The hasNextDouble() is a method of Java Scanner class which is used to check if the next token in this scanner's input can be interpreted as a double value using the nextDouble() method. It returns true if the scanner's input can be interpreted as a double value, otherwise returns false.

Syntax

Following is the declaration of hasNextDouble() method:

Parameter

This method does not accept any parameter.

Returns

The hasNextDouble() method returns true if and only if this scanner's next token is a valid double value.

Exceptions

IllegalStateException

Compatibility Version

Java 1.5 and above

Example 1

Output:

Found Double Value: 22.10
Not Found Double Value: Double
Not Found Double Value: number
Not Found Double Value: is
Found Double Value: 2123324.58

Example 2

Output:

Found Double Value: false
Scan String: Hello
Found Double Value: false
Scan String: World!
Found Double Value: true
Scan String: 12
Found Double Value: false
Scan String: +
Found Double Value: true
Scan String: 13.0
Found Double Value: false
Scan String: =
Found Double Value: true
Scan String: 15
Found Double Value: true
Scan String: 2.123

Example 3

Output:

Enter some value: JavaTpoint
Please Entered the Double Value.
You entered: JavaTpoint

Enter some value: 12345.66
Your entered value: 12345.66

Next TopicJava Scanner Class



Help Others, Please Share

facebook twitter pinterest