+ 7
Switch case - question
How is this result 17? I don't get it: int x = 3; switch(x){ case 1: x+=x; case 3: x+=x; case 5: x+=x; default: x+=5; } System.out.print(x);
3 odpowiedzi
+ 9
OK, now I realize there's no "break;" statement. Now I get it. Sorry for the unnecessary question.
0
first u use the break statement . break statement break the switch case. and we get the result 6
0
Easy to miss break statements, or to miss that they aren't there when you are looking at some code you've not looked at in a while. There is one reason why you wouldn't want to put in a break - if there are some scenarios when you need additional code first, but I guess those are fairly rare (so she they do happen they could catch you out)