What is y after the following switch statement is executed? Rewrite the code using an if-else statement.
x = 3; y = 3;
switch (x + 3) {
case 6: y = 1;
default: y += 1;
}
After this switch statement y=2. Because in case 6 we don't write a "break;" and 2 condition are performed.
if(x+3==6){
y=1;
}
else{
y+=1;
}
Comments
Leave a comment