0

I need some help with scanners. Anyone?

23rd Aug 2016, 11:56 AM
bdubs5050
bdubs5050 - avatar
2 Réponses
+ 1
what do you mean? like how to let the user interact with your program if so th code is: playerAnswer = scan.nextLine (); im sure you know about if, else, and else if statements so just do that for your users options. and if your doing a console game and want to make sure the user can only type one of the options, put that code and the other statements within a while loop thats set to true. the reason why you should do this is because if for example you have two options apple and pear and the player says orange. if you put a message in there some where saying "sorry, answer not recognized" it will say that message and repeat the question. hope that helped :)
23rd Aug 2016, 12:32 PM
Aquarius
Aquarius - avatar
+ 1
scanner is used to get input in java by user......it is one of many input taking way in java....gor example if u want to add numbers taken from user then use scanner to take input from user i.e integer
3rd Aug 2017, 2:27 PM
Shobh
Shobh - avatar