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; } } }
6 Réponses
+ 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.
+ 1
there is no break statement in the default case
0
use break statement before starting new case and use one default statement
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
0
thank u everyone
0
chu...😂