0

User input in java ?

Can anyone plz explain how do we take user input in java .I didnt quite understand the module ...

31st Mar 2018, 4:36 AM
Amitesh Shrey
Amitesh Shrey - avatar
2 Answers
+ 1
One of the easiest way for user input is to use a Scanner object. Scanner scan = new Scanner(System.in); //Reads from System.in System.out.println("Enter a number"); int x = scan.nextInt(); //Scans the input of Integer type scan.close(); //once finished close scanner https://code.sololearn.com/czaZjwJ5fBz1/?ref=app https://www.sololearn.com/learn/Java/2220/
31st Mar 2018, 4:45 AM
Nilesh
Nilesh - avatar
+ 1
If you have just started learning java, I'll recommend you to take a look at how to take input using command line arguments. They are easy to understand. You'll understand scanner and buffered reader classes better once you will complete input/output streams in java.
31st Mar 2018, 10:51 AM
Nikhil Sharma
Nikhil Sharma - avatar