Java Scanner hasNextFloat() Method

The hasNextFloat() 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 float value using the nextFloat() method. It returns true if the scanner's input can be interpreted as a float value, otherwise returns false.

Syntax

Following is the declaration of hasNextFloat() method:

Parameter

This method does not accept any parameter.

Returns

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

Exceptions

IllegalStateException

Compatibility Version

Java 1.5 and above

Example 1

Output:

Result: false
Scan String: JavaTpoint.com!

Example 2

Output:

Scan String: Hello
 false
Scan String: World!
 true
Scan String: 12
 false
Scan String: +
 true
Scan String: 13.0
 false
Scan String: =
 true
Scan String: 15.00
 true
Scan String: 2.123

Example 3

Output:

Please enter value: 454.787
Your entered value: true