
- 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
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 Questions & Answers
- The String in Switch Case in Java
- Switch case in Arduino
- Switch case statement in C
- Switch Case in Python (Replacement)
- Switch case calculator in JavaScript
- How to use case-insensitive switch-case in JavaScript?
- How to use an enum with switch case in Java?
- What is Switch...case statement in JavaScript?
- Explain nested switch case in C language
- Using range in switch case in C/C++
- Case sensitive string comparison in Java.
- How to implement switch-case statement in Kotlin?
- Java program to generate a calculator using the switch case
- Java Program to Make a Simple Calculator Using switch...case
- Please explain what happens when PHP switch case executes case 0?
Advertisements