Problem statement:
Write a program for switch statements using enum in Java.
Write a program for switch statements using enum in Java.
- enum APP {
- Google, Yahoo, Apple, HP
- }
- public class SwitchStatement {
- public static void main(String[] args) {
- APP c = APP.Google;
- switch (c) {
- case Apple:
- System.out.println("You choose Apple.");
- break;
- case Google:
- System.out.println("You choose Google.");
- break;
- case Yahoo:
- System.out.println("You choose Yahoo.");
- break;
- case HP:
- System.out.println("You choose HP.");
- break;
- default:
- System.out.println("default");
- break;
- }
- }
- }
Output:
You choose Google.
No comments:
Post a Comment