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: ...

7th Jul 2016, 6:48 AM
Raj shah
Raj shah - avatar
3 Respostas
+ 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
7th Jul 2016, 6:59 AM
James
James - avatar
+ 1
Yup👍 Single character are in single inverted comma 'a'
7th Jul 2016, 7:06 AM
Raj shah
Raj shah - avatar
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?
7th Jul 2016, 12:34 PM
Antonio Hu