Lessons

Java tutorial

Java Switch

switch compares one value with several case labels. break leaves the switch. Without it, execution can continue into the next case. default runs when no case matches.

Example

Edit the code and run it again. This runner stays in your browser and covers the syntax used in these lessons.

Output

Run the example to see output here.

What this code does

day matches case 3, so the program prints Wednesday and break stops the switch before default can run.