Using Scanner Class:
Scanner class is used to get input from the user, to use this class, you will have to import java.util.scanner package.
Get Input from User program in Java
Common functions to get input
| Method |
Description |
| next() |
to get string without space from the user |
| nextLine() |
to get string with spaces from the user |
| nextInt() |
to get integer value from the user |
| nextFloat() |
to get float value from the user |
| nextByte() |
to get byte value from the user |
In this program we will read Name, Gender, Age and Float and then print all inputted values.
Output
Enter name: Mike the Expert Enter Gender (Male/Female): Male Enter age: 21 Enter weight: 65.50 Name: Mike the Expert Gender: Male Age: 21 Weight: 65.5
need an explanation for this answer? contact us directly to get an explanation for this answer