- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
String in Switch Case in Java
A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case.
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
Well done Your grade is C
- Related Articles
- The String in Switch Case in Java
- Switch case in Arduino
- Switch case statement in C
- Switch case calculator in JavaScript
- Switch Case in Python (Replacement)
- How to use case-insensitive switch-case in JavaScript?
- How to use an enum with switch case in Java?\n
- Case sensitive string comparison in Java.
- What is Switch...case statement in JavaScript?
- Explain nested switch case in C language
- Using range in switch case in C/C++
- Java program to generate a calculator using the switch case
- Java Program to Make a Simple Calculator Using switch...case
- What is a switch case statement in Java and how to use it?
- How to implement switch-case statement in Kotlin?

Advertisements