Javatpoint Logo
Javatpoint Logo

Java Scanner nextFloat() Method

The 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.


Following is the declaration of nextFloat() method:


This method does not accept any parameter.


The nextFloat() method returns the Float scanned from the input.


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


Enter the amount: 263426
Enter the Total Balance: 3434343.454
New Balance is: 3170917.0

Example 2


Input value : 
Exception in thread "main" java.lang.IllegalStateException: Scanner closed
	at java.base/java.util.Scanner.ensureOpen(
	at java.base/
	at java.base/java.util.Scanner.nextFloat(
	at myPackage.ScannerNextDoubleExample2.main(

Example 3


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 4


Enter the numeric value : 74537453.56959
Float value : 7.4537456E7 
Twice value : 1.49074912E8
Next TopicJava Scanner Class

Help Others, Please Share

facebook twitter pinterest