switch case Statement in Java Programming
In this lesson, we will understand what is switch case statement, and how it works in a Java Programming with the help of examples.
What is switch case Statement
In Java program a switch case statement is used to check if an expression's value matches any value in a given list. Each value in the list is associated with a label called a case. If the expression's value matches a case value, the code inside that case runs. If the expression's value doesn't match any case value, the default case runs, but the default case is optional.
In each case, a break statement is used at the end to stop the switch from checking any more cases if the expression's value matches that case.
switch(expression)
{
case value1:
// statements
break;
case value2:
// statements
break;
// you can have any number of case statements.
default: // Optional
// default statements
}
Unlock This Lesson & Start Learning!
Get full access to this lesson, practical exercises, quizzes, and your Mentora AI Tutor.
Special Offer, use coupon code DWL6BC to get additional discount of 10% on all subscription. Hurry limited time offer.
1 Month
Renews at ₹259/month.
Manual renewal required.
No automatic charges.
- Premium lessons access
- Quizzes and exercises
- Mentora AI Tutor
3 Months
Equivalent to ₹219.67/month.
Manual renewal required.
No automatic charges.
- Premium lessons access
- Quizzes and exercises
- Mentora AI Tutor
6 Months
Equivalent to ₹193.17/month.
Manual renewal required.
No automatic charges.
- Premium lessons access
- Quizzes and exercises
- Mentora AI Tutor
12 Months
Equivalent to ₹179.92/month.
Manual renewal required.
No automatic charges.
- Premium lessons access
- Quizzes and exercises
- Mentora AI Tutor