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

28th Jan 2017, 5:31 AM
Sambit Mohapatra
Sambit Mohapatra - avatar
14 Respostas
+ 10
8
22nd Mar 2018, 6:49 PM
Alexandr Zhidenko
+ 7
8. Just put it in the code playground...
28th Jan 2017, 5:54 AM
Jafca
Jafca - avatar
+ 7
How is it 2? There are no break statements...
28th Jan 2017, 2:37 PM
Jafca
Jafca - avatar
+ 6
No break statements... 8
2nd Feb 2017, 2:25 PM
Zh3k4
Zh3k4 - avatar
+ 4
8
3rd Feb 2017, 8:52 AM
Smit Shah
Smit Shah - avatar
+ 3
Downvoted for the right answer lol
28th Jan 2017, 2:42 PM
Jafca
Jafca - avatar
+ 3
8
25th Sep 2018, 8:55 AM
Codeie
Codeie - avatar
+ 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
25th Sep 2018, 7:16 AM
Jayank Aghara
Jayank Aghara - avatar
0
2 4 8
10th Sep 2018, 5:27 PM
Killer
Killer - avatar
- 2
2
31st Jan 2017, 11:16 PM
Olatunde Omotolani
Olatunde Omotolani - avatar
- 2
2
12th Feb 2017, 7:29 PM
Nakshatra Gupta
Nakshatra Gupta - avatar