+ 1

how to take input from user with exmple

5th Aug 2016, 2:37 PM
Shyam sunder Reddy
Shyam sunder Reddy - avatar
4 Antworten
+ 2
Simply Google search the Scanner class. You will find many examples
5th Aug 2016, 2:58 PM
Mitch K
Mitch K - avatar
+ 2
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 :)
5th Aug 2016, 3:05 PM
Aquarius
Aquarius - avatar
+ 1
you can take input by using BufferedReader class and Scanner clsss
5th Aug 2016, 7:28 PM
sachin tomar
sachin tomar - avatar
0
here is how i do it: Scanner scannerVariable = new Scanner(System.in); String userInput; //This scans for input and stores it in the string userInput = scannerVariable.nextLine();
8th Aug 2016, 1:46 AM
Edward