+ 1
Why we took input in java with import and scanner...explain pls
6 Answers
+ 2
import statement is used to include the scanner class which is predefined in java to your program.
Scanner is a class in java. util package used for obtaining the input of the primitive types like int, double, etc. and strings. It is the easiest way to read input in a Java program
Follow this link to know more: https://www.geeksforgeeks.org/scanner-class-in-java/
+ 2
Dushyant Bhardwaj Already answered that a Scanner is a class pre defined in java.util package. It is used to obtain input from a user while the program is running.
String args[] is basically an array which is used to pass argument to the program when you are executing it from the command line.
If you are using scanner class you can omit the String args[] and your program will run without any error.
0
*args
0
Thanku soo much
0
You actually dont need to do that to take input. (I think) I am pretty sure that the scanner utility is written in java, so you could theoretically write the code for taking input in the code itself. Its a lot easier to just use the scanner though.
- 1
But whats the main use of scanner and import in java and why we write string agrs just next to main function...