+ 1

Does anybody know how to create more than one scanner object in a program? I'd like to write a question-answer program...

multiple scanner objects

16th Dec 2017, 1:32 PM
noura
noura - avatar
8 Answers
+ 2
@noura Would you like to make multiple objects of the same Scanner, or are you wanting to make a program that uses multiple Scanners?
22nd Dec 2017, 12:13 AM
Jacob Duelz
Jacob Duelz - avatar
+ 2
@noura Okay. I've been researching it and experimenting a bit, and I don't think that you can use one Scanner for multiple inputs, at least not by assigning a value to the variable again with the new keyword. I know that you can do something like it in C++, but not as far as I've seen in Java. I can try to help you figure something out to compensate for it, though. I'll keep researching to see if I can come up with something.
23rd Dec 2017, 9:35 PM
Jacob Duelz
Jacob Duelz - avatar
+ 2
You can use a BufferedReader to accept multiple inputs with a single object. Here's a demonstration ( https://code.sololearn.com/cjXE9y44ZtEA/?ref=app ). Let me know if this helps or if you need me to explain it.
23rd Dec 2017, 11:31 PM
Jacob Duelz
Jacob Duelz - avatar
+ 1
With java?
16th Dec 2017, 1:45 PM
Kostas Batz
Kostas Batz - avatar
+ 1
yes
16th Dec 2017, 6:14 PM
noura
noura - avatar
+ 1
well, i think i want to use the same scanner object more than once
23rd Dec 2017, 1:54 PM
noura
noura - avatar
+ 1
@noura Okay. Are you wanting to use the value more than once, or do you want to use the same Scanner to accept different inputs?
23rd Dec 2017, 4:05 PM
Jacob Duelz
Jacob Duelz - avatar
+ 1
i want to use different inputs. the program asks questions and the user has to answer.
23rd Dec 2017, 8:20 PM
noura
noura - avatar