bellow code giving output as monday Tuesday Wednesday I am expecting only monday Tuesday. is that true?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

bellow code giving output as monday Tuesday Wednesday I am expecting only monday Tuesday. is that true??

public class Program { public static void main(String[] args) { int day = 1; switch(day) { case 1: System.out.println("Monday"); default: System.out.println("Tuesday"); case 3: System.out.println("Wednesday"); break; } } }

9th Jul 2016, 12:19 PM
Anup Shetty
6 Answers
+ 2
use default at the last and write cases above it and use break statement after every case. the thing that u r expecting is right.
10th Jul 2016, 4:59 PM
K.p.
+ 1
there is no break statement in the default case
9th Jul 2016, 1:29 PM
Rayen Ochi
Rayen Ochi - avatar
0
use break statement before starting new case and use one default statement
9th Jul 2016, 6:25 PM
Jayanti Dikshit
0
the best practice is to put default at the last since it is used to check if there is no matching value with your case. and you should put break statement in every case, while in default there is no need to put break statement
11th Jul 2016, 5:08 AM
Harry Marwanto
Harry Marwanto - avatar
0
thank u everyone
11th Jul 2016, 8:13 AM
Anup Shetty
0
chu...😂
31st Jul 2016, 4:26 AM
Vedant Kadam
Vedant Kadam - avatar