Home » , » java - user input

java - user input

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

0 comments:

Post a Comment

Popular Posts

GENRES

 
Copyright ©

latest code update bloggingskillBest coding website in india

Created By Sora Templates | Distributed By Gooyaabi Templates