Java – User Input

To get input from a user in Java, use the Scanner class. The java.util package has the Scanner class. First, import the Scanner:

Read a string value from the user in Java

To read the strings, we have used the nextLine() method. Let us see an example wherein we are asking the user to enter the country name:

Output

Read a boolean value from the user in Java

To read a boolean value, we have used the nextBoolean() method. Let us see an example wherein we are asking the user to enter the True or False values for the result:

Output

Read a double value from the user in Java

To read a double value, we have used the nextDouble() method. Let us see an example wherein we are asking the user to enter the points:

Output

Read an int value from the user in Java

To read an integer value, we have used the nextInt() method. Let us see an example wherein we are asking the user to enter the marks:

Output


If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


For Videos, Join Our YouTube Channel: Join Now


Java Exception Handling
Java Regular Expressions
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading