Today we are going to learn that how we can take input from user in Java or core Java.
First of all, we have to create a file with any name but file must having .java extension. After that we have to open that file in any of the editor to write the code inside the file.
We will write code like this, see above diagram
In the code there are some terminologies,
This commond is used to import a packege named util, which has all the class for taking input from the user, like Scanner etc.
sc is the object of the Scanner class and nextint() is the method to take input from the user.
We will use the command to compile and execute the program:
For compile:- javac New.java For run:- java New After executing it will return following output.
So this is how we will take input from user in Java in most simple way.
Still you have any doubts in this program then you can comment below to get the quick answer.
Thanks for reading the post.
Hey Thank you so much, I learn that how to take input from user in Java. Thanks once again