Answer to Question #319978 in Java | JSP | JSF for Sammy

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;

}



1
Expert's answer
2022-03-29T07:41:09-0400

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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS