java boolean switch case code example
Example 1: java switch
int day = 4;
switch (day) {
case 6:
System.out.println("Today is Saturday");
break;
case 7:
System.out.println("Today is Sunday");
break;
default:
System.out.println("Looking forward to the Weekend");
}
// Outputs "Looking forward to the Weekend"
Example 2: can switch statements in java work with boolean
The expression in the switch statement must be of type char, byte, short, or int. It cannot be boolean, float, double, or String.