0

Switch output

Why the result is 15.0?? public class Program { public static void main(String[] args) { float x=9,y=5; int z= (int) (x/y); switch (z){ case 1: x=x+2; case 2: x=x+3; case 3: x=x+1;} System.out.println (x); } }

5th May 2018, 4:29 PM
Jakub ⚡
Jakub ⚡ - avatar
5 Answers
+ 6
No break statements were present in the switch block. All cases were executed. The resulting value of x is 15.0.
5th May 2018, 4:35 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
break; is missing.
5th May 2018, 4:34 PM
Yugabdh
Yugabdh - avatar
0
public class Program { public static void main(String[] args) { int x=9,y=5; int z; z=(int)(x/y); switch (z){ case 1: x=x+2; break; case 2: x=x+3; break; case 3: x=x+1; break; } System.out.println (x); } } /*correction*/
5th May 2018, 4:37 PM
Yugabdh
Yugabdh - avatar
0
oh yes, that simple. thank you
5th May 2018, 4:40 PM
Jakub ⚡
Jakub ⚡ - avatar
0
Yes
26th Jul 2020, 5:15 AM
Abhishek_singh
Abhishek_singh - avatar