Question #319978

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;

}



Expert's answer

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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS