Scanner nextfloat Java

Scanner nextfloat Java

As the name of the method says, using this method, we can take some float type user input.

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
float floatdata = scanner.nextFloat();
System.out.println(floatdata);
}
}

So, we get the float data as input from the user, and then we output whatever float data was given as an input from the user.

You can write whatever there is inside the main method, but take care of other things, like the name of the program(it should be the same as the name of the class which contains the main method) and the package name. If you are writing the package name in your program and no such package is present, then it may create a problem.

You can try implementing the above program and observe the output. I have created a float variable to store the user input data and then printed the same data to the console.