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, switch case statement is simplified form of the Java Nested if else statement , it helps to avoid 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.

Recommended:-  Java Logical Operators

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.