Java Scanner hasNextDouble() MethodThe 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. SyntaxFollowing is the declaration of hasNextDouble() method: ParameterThis method does not accept any parameter. ReturnsThe hasNextDouble() method returns true if and only if this scanner's next token is a valid double value. ExceptionsIllegalStateException Compatibility VersionJava 1.5 and above Example 1Output: 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 2Output: 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 3Output: 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
|