Page 82 - TP_iPlus_V2.1_Class8
P. 82
For example:
public class SwitchStatement
{
public static void main(int dayNumber)
{
switch (dayNumber) {
case 1:
System.out.println("Today is Monday");
break;
case 2:
System.out.println("Today is Tuesday");
break;
case 3:
System.out.println("Today is Wednesday");
break;
case 4:
System.out.println("Today is Thursday");
break;
case 5:
System.out.println("Today is Friday");
break;
case 6:
System.out.println("Today is Saturday");
break;
case 7:
System.out.println("Today is Sunday");
break;
default:
System.out.println("Invalid day number");
}
}
}
After compiling the preceding program, run it twice
and enter values 6 and 8. When you enter the value
6, the case 6 will be executed and the output “Today
is Saturday” will be displayed on the terminal.
Output
80
iPlus (Ver. 2.1)-VIII

