+ 7
What's the output ?
public class Demo { public static void main(String[] args) { int i=1; switch(i) { case 1: i+=i; case 2: i+=i; default: i+=i; } System.out.println(i); } }
11 Answers
+ 10
8
+ 7
8. Just put it in the code playground...
+ 7
How is it 2? There are no break statements...
+ 6
No break statements... 8
+ 4
8
+ 3
Downvoted for the right answer lol
+ 3
8
+ 2
output:
8
because of there is no break: statement so all code will execute from case 1...
in case 1
i= 1+1
case 2
i= 2+2
default
i= 4+4
0
2
4
8
- 2
2
- 2
2