Programming
Java User Input
Java User Input
The Scanner class is used to get user input, and it is found in the java.util
package.
To get the instance of Java Scanner which reads input from the user, we
need to pass the input stream (System.in) in the constructor of Scanner
class.
Scanner in = new Scanner (System.in);
To use the Scanner class, create an object of the class and use any of
the available methods found in the Scanner class documentation. In our
example, we will use the nextLine() method, which is used to read
Strings:
Output:
Input Types
In the previous example, we used nextLine() method which is used to read Strings. To read other types, look at the table below.
Output:
Output:
Activity
Design a program that will display your 20 personal information using Java
Input. Show your code and output.
THANK YOU
Java User Input