Java Scanner nextFloat() MethodThe nextFloat() method of Java Scanner class is used to scan the next token of the input as a Float. If the translation is successful, the scanner past the input that matched. SyntaxFollowing is the declaration of nextFloat() method: ParameterThis method does not accept any parameter. ReturnsThe nextFloat() method returns the Float scanned from the input. ExceptionsInputMismatchException- 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 VersionJava 1.5 and above Example 1Output: Enter the amount: 263426 Enter the Total Balance: 3434343.454 New Balance is: 3170917.0 Example 2Output: Input value : Exception in thread "main" java.lang.IllegalStateException: Scanner closed at java.base/java.util.Scanner.ensureOpen(Scanner.java:1150) at java.base/java.util.Scanner.next(Scanner.java:1573) at java.base/java.util.Scanner.nextFloat(Scanner.java:2496) at myPackage.ScannerNextDoubleExample2.main(ScannerNextDoubleExample2.java:9) Example 3Output: Not Found Float: Hello Not Found Float: World! Found Float: 12.0 Not Found Float: + Found Float: 13.43 Not Found Float: = Found Float: 15.43 Not Found Float: 2.123 Example 4Output: Enter the numeric value : 74537453.56959 Float value : 7.4537456E7 Twice value : 1.49074912E8 Next TopicJava-scanner-nextint-method |