Got a quick question about using the scanner class - which I'm not too familiar with.
Let's say I'm making a command line interface, something really simple like press 1 for this, 2 for that.
Now I have a method called menu() that creates a new Scanner (Scanner in = new Scanner(System.in);). It then grabs the int from there, and depending on the number, calls another method.
My problem is, in my other methods where input is required... how do I "enable" it again. It's not letting me input anything apart from the first time.
Do I need to create another new Scanner for that method, or can I use the same one system wide?
Question
Fid
Hey all,
Got a quick question about using the scanner class - which I'm not too familiar with.
Let's say I'm making a command line interface, something really simple like press 1 for this, 2 for that.
Now I have a method called menu() that creates a new Scanner (Scanner in = new Scanner(System.in);). It then grabs the int from there, and depending on the number, calls another method.
My problem is, in my other methods where input is required... how do I "enable" it again. It's not letting me input anything apart from the first time.
Do I need to create another new Scanner for that method, or can I use the same one system wide?
Help please :D:D
Link to comment
Share on other sites
4 answers to this question
Recommended Posts