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.
3 ответов
+ 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.
+ 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
+ 1
https://code.sololearn.com/cV1y9IvHbTzK/#
as a small example