

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- Java break statement with switch
- Java switch statement
- Java switch statement example
- Switch Statement in Java
- Can we use Switch statement with Strings in java?
- PHP switch Statement
- Java Program to Implement switch statement on strings
- Switch case statement in C
- MySQL If statement with multiple conditions?
- Explain switch statement in C language
- How to use PowerShell Break statement with the Switch command?
- Kotlin 'when' statement vs Java 'switch'
- What is Switch...case statement in JavaScript?
- Explain Strict Comparison in JavaScript switch statement?
- Can you use a switch statement around an enum in Java?
Advertisements