Java

Java Switch Case Examples3 min read

In this example, I will show you how to use switch case statement with a few examples. Before examples let me explain what is the switch statement.

What is Switch statement

The switch statement evaluates an expression, matching the expression’s value against a series of case clauses, and executes statements after the first case clause with a matching value, until a break statement is encountered. The default clause of a switch statement will be jumped to if no case matches the expression’s value.




Syntax

Switch Case Examples in Java

Example 1: Enter the favorite color and print answer.(Java String Example)

Output:

Example 2: Switch example with Scanner

Output:

Example 3 Enter month number then show month name.

Output:

Example 4: Java switch case multiple values

Output:

Example 5: Switch case with Enum

Output:

Example 6:

Output:

Leave a Comment