Java Switch Case Statement

In this tutorial you will learn about the Java Switch Case Statement and its application with practical example.

Java Switch Case Statement

In Java, a switch case statement is a simplified form of the Java Nested if-else statement, it helps to avoid a long chain of if..else if..else statements. A switch-case statement evaluates an expression against multiple cases in order to identify the block of code to be executed.

Java Switch Case Flow Diagram

cpp-switch-case-statement-flowchart

Syntax:-

Example:-

In the above program we have an integer variable dayOfWeek with initial value of 5, and we pass this variable as expression to following switch statement, value of dayOfWeek is tested with multiple cases to identify the block of code to be executed.

When we run the above java program, will see the following output –

Output:-

java_switch_case_statement_example

In this tutorial we have learn about the Java Switch Case Statement and its application with practical example. I hope you will like this tutorial.