0
Can we write Char day =b; switch (day) case a: ...... case b: .... case c: ... instead of int day =3; switch(day) case 1: .. case 2: .... case 3: ...
3 Answers
+ 1
absolutely. keep in mind char is 'a' not just a. String is "word". switches are just another version of nested if statements. The item following case is what your comparing the variable to. It can be strings, characters, ints.Saying Char day ='b'; then doing switch(day) is always going to do the code under case 'b' because that's the value of the day variable. Saying case is essentially saying if(day == 'a'). if it doesn't, it moves to the next case if(day == 'b'). which it does, it'll execute that code
+ 1
Yupđ
Single character are in single inverted comma 'a'
0
from what i understood from the 2nd quiz is that if you have 3 INT and even if one of them is true it will not result the default value, is this correct?