Saved Bookmarks
| 1. |
Can we use a string in the switch case in java? |
|
Answer» Yes, Java ALLOWS you to use strings in switch case conditions. Below is a Java PROGRAM that shows the use of string in switch case. Example: public class StringinSwitchCase { public static VOID main(String[] args) { String fruit = "APPLE"; switch(fruit) { case "Mango": System.out.println("Sweet"); break; case "Apple": System.out.println("Delicious"); break; case "ORANGE": System.out.println("Luscious"); break; default: System.out.println("Not a fruit"); } }}Output: Delicious |
|