+ 1
write a Java program to illustrate the use of switch statement
answer pls
3 Answers
+ 3
Joe, you are missing default. If day is not in cases.
+ 2
Thank you Wachirakorn. I will fix it. I agree, switch statement must have a default or you can get error.
0
// switch
public class Program {
public static void main(String[] args) {
int day = 3;
switch(day) {
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
case 3:
System.out.println("Wednesday");
break;
default:
System.out.println("The other 4 days");
}
}
}