0
Why is output 17? it is calculated as follows: case 1( x= 3+3=6, case 3 (x=6+3=9), case 5 (x=9+3=12) , default (x=12+5=17)?
5 Respuestas
+ 1
It is:
switch(3) because x = 3;
So it goes straight to case 3:
(x = x + x = 6)
Then it goes to case 5 because there is no break:
(x = x + x = 12)
Then it goes to default case cuz there is again no break:
(x = x + 5 = 17)
+ 1
There aren't any breaks in this switch case, so the code just go through every case after the one it matched.
If you want the behavior to change, you can add the break explicitly: {x+=x; break;}
0
Is it so calculate?
0
Can you explain me why it so?
0
x=3
x= x+x = 3+3 =6
Then x=6
x = x+x = 6+6 =12
Then x=12
x = x+5 = 12+5 =17