+ 1

Why we took input in java with import and scanner...explain pls

20th Nov 2020, 11:58 AM
Dushyant Bhardwaj
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/
20th Nov 2020, 8:46 PM
Souptik Nath
Souptik Nath - avatar
+ 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.
21st Nov 2020, 4:34 AM
Souptik Nath
Souptik Nath - avatar
0
*args
20th Nov 2020, 12:20 PM
Dushyant Bhardwaj
0
Thanku soo much
20th Nov 2020, 12:39 PM
Dushyant Bhardwaj
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.
21st Nov 2020, 4:17 PM
Aria
Aria - avatar
- 1
But whats the main use of scanner and import in java and why we write string agrs just next to main function...
20th Nov 2020, 12:19 PM
Dushyant Bhardwaj