+ 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
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?
+ 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.
+ 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.
+ 1
With java?
+ 1
yes
+ 1
well, i think i want to use the same scanner object more than once
+ 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?
+ 1
i want to use different inputs. the program asks questions and the user has to answer.