In: Computer Science
What will the following code segments print on the screen?
int num = 3;
switch (num){
case 1:
System.out.println(“Spring”);
case 2:
System.out.println(“Summer”);
case 3:
System.out.println(“Autumn”);
case 4:
System.out.println(“Winter”);
}
Thanks for the question
===================================================================
The code will output
Autumn
Winter
Since we are not using break statement, in Case 3 , the cases below Case 3 will also get executed.
Here is the output screenshot when you run it -
If we use break statement like below it will only print Autumn