0

About switch this concept

public class Program { public static void main(String[] args) { int day = 1; switch(day) { case 1: System.out.println("Monday"); case 2: System.out.println("Tuesday"); case 3: System.out.println("Wednesday"); } } } for this program the output is Monday Tuesday Wednesday How is it possible?

7th Nov 2020, 4:27 AM
Naveen Thotada
Naveen Thotada - avatar
3 odpowiedzi
+ 10
Since there is no break statement along with the case stmt ,therefore fall through happens.
7th Nov 2020, 4:33 AM
Alphin K Sajan
Alphin K Sajan - avatar
+ 7
Because there is no break
7th Nov 2020, 4:39 AM
🔰Saurabh🔰
🔰Saurabh🔰 - avatar
+ 6
Dont know much about java... But you need to add breaks after every case Check out the SL java course for more
7th Nov 2020, 4:33 AM
Shreyansh
Shreyansh - avatar