+ 1

Why does not switch condn work with char or any other one just only with int

In code play as provided in this app switch case works only with int values not with char or any other one

11th Jul 2019, 9:52 AM
Nishant Singh
Nishant Singh - avatar
5 Answers
+ 2
Nishant Singh That's not correct. try this: char c = 'a'; switch(c){ case 'a': System.out.println("a"); break; case 'b': System.out.println("b"); }
11th Jul 2019, 1:11 PM
Denise Roßberg
Denise Roßberg - avatar
11th Jul 2019, 1:43 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
You must be talking about Java. It works in C.
11th Jul 2019, 10:59 AM
Sonic
Sonic - avatar
+ 1
Sonic In java switch works with int, char and enums.
11th Jul 2019, 1:06 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Denise robberg the code of switch you give me has 'a' this written in println box how it is working you have to write "a" to give msg.
15th Jul 2019, 1:34 PM
Nishant Singh
Nishant Singh - avatar