0

How would you get the user input in a switch

I don't know completely how scanners work aswell so if you can or want to explain it fully thanks. PS Tashi N sorry for being a D*** in my last question.

28th Mar 2017, 9:55 PM
Daniel
Daniel - avatar
3 Respostas
+ 3
use the scanner to store user input in a variable. use the variable as argument of the switch case: http://docs.oracle.com/javase/7/docs/technotes/guides/language/strings-switch.html ps You shold post your apology in the relative thread, here is irrelevant.
28th Mar 2017, 10:28 PM
seamiki
seamiki - avatar
+ 1
//initialize s with standard input stream Scanner s = new Scanner(System.in); //check if s has any input then return it as a String if(s.hasNext()) String str = s.nextLine(); //SAB but with int if(s.hasNext()) int i = s.nextInt() if(s.hasNext()) double d = s.nextDouble() and so on and so forth for each datatype (except for char) to use in a switch assign input to a variable then declare a switch with that variable
28th Mar 2017, 10:21 PM
Logan New
Logan New - avatar
28th Mar 2017, 10:25 PM
T0nd3