+ 13

Module To Accept User Input???

What module must be imported to accept user input in Java? A. java.util B. java.io Why the answer is B?? Why it isn't A??

21st Dec 2017, 6:08 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
11 ответов
+ 33
it depends on your requirements. So, if you are ok with Scanner, you will use java.util package. But in a big commercial projects, most of times you will use FileInputStream which is in java.io package.
22nd Dec 2017, 8:14 AM
Ghena Ramascan
Ghena Ramascan - avatar
+ 16
Technically, both answers are correct. According to your question either one can be used to take user input (java.util.Scanner as well as java.io.BufferedReader.) Just for a note: BufferedReader is used with InputStreamReader)
21st Dec 2017, 6:13 AM
Dev
Dev - avatar
+ 16
InputStream must be imported to accept user input in java and InputStream is from java.io. System.in is an InputStream so you don't really need to import java.io. btw io means input output so it would make sense for B to be the answer.
21st Dec 2017, 9:15 AM
qwerty
qwerty - avatar
+ 12
The question is flawed. Either it should had been a multiple correct answer or only one option of both should had been provided. The answer is both (java.io.BufferedReader and java.util.Scanner) btw.
21st Dec 2017, 6:17 AM
Divesh Singh
Divesh Singh - avatar
+ 10
Oh thanks @Mickel Sánchez! Of course, we need to report it. Never knew that it was a challenge question, my bad... 😅
21st Dec 2017, 8:26 AM
Dev
Dev - avatar
+ 9
Thanks Dev😉
21st Dec 2017, 6:15 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 7
@Dev, I think this is actually a question about a challenge So, report the challenge could be useful to modify the question correctly. At the moment it is quite diffuse and contains errors as already indicated
21st Dec 2017, 8:19 AM
Mickel
Mickel - avatar
+ 6
As they said, both are correct (maybe you should notify that, so the quiz is modified)
21st Dec 2017, 6:20 AM
Mickel
Mickel - avatar
+ 2
I remember that the user input is made with java.util.Scanner and you make an object with the Scanner class or something like that.
21st Dec 2017, 9:14 PM
Catalin Popinciuc
Catalin Popinciuc - avatar
+ 1
The only difference is when you import only scanner , it’s only imports Scanner. If you import whole thing thing util.*; , it imports everything from Util.
23rd Dec 2017, 2:35 AM
Ajay Reddy
Ajay Reddy - avatar
0
You can use it by adding import java.util.*; Or Import java.util.Scanner;
23rd Dec 2017, 2:33 AM
Ajay Reddy
Ajay Reddy - avatar