- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java switch statement with multiple cases.
Following is the required program.
Example
public class Test { public static void main(String args[]) { // char grade = args[0].charAt(0); char grade = 'C'; switch(grade) { case 'A' : System.out.println("Excellent!"); break; case 'B' : case 'C' : System.out.println("Well done"); break; case 'D' : System.out.println("You passed"); case 'F' : System.out.println("Better try again"); break; default : System.out.println("Invalid grade"); } System.out.println("Your grade is " + grade); } }
Output
Compile and run the above program using various command line arguments. This will produce the following result −
Well done Your grade is C
- Related Articles
- Java break statement with switch
- Java switch statement
- Switch Statement in Java
- Java switch statement example
- Can we use Switch statement with Strings in java?
- PHP switch Statement
- Java Program to Implement switch statement on strings
- How to override multiple if-else conditions using a switch statement in TypeScript?
- Kotlin 'when' statement vs Java 'switch'
- MySQL If statement with multiple conditions?
- What are the rules to be followed while working with a switch statement in java?
- Switch case statement in C
- How to use PowerShell Break statement with the Switch command?
- Can you use a switch statement around an enum in Java?
- How to define a switch statement in JShell in Java 9?

Advertisements