Pin It

A simple Java program demonstrating how to use enum in switch statements

Program to demonstrate how to use enum in switch statements in Java

package com.hubberspot.examples;

import java.util.Scanner;

enum IndianPremierLeague {

 DECCAN_CHARGERS,
 KOLKATA_KNIGHT_RIDERS,
 MUMBAI_INDIANS,
 CHENNAI_SUPER_KINGS,
 RAJASTHAN_ROYALS,
 ROYAL_CHALLENGERS_BANGALORE,
 KINGS_XI_PUNJAB,
 PUNE_WARRIORS,
 DELHI_DAREDEVILS

}

public class SwitchEnumTest {


   public static void main(String[] args) {

 IndianPremierLeague team = IndianPremierLeague.MUMBAI_INDIANS;

 System.out.print("So you like: ");

 switch (team) {

           case DECCAN_CHARGERS:
  System.out.println("Deccan Chargers"); 
  break;

           case KOLKATA_KNIGHT_RIDERS:
  System.out.println("Kolkata Night Riders"); 
  break;

    case MUMBAI_INDIANS:
  System.out.println("Mumbai Indians"); 
  break;
   
           case CHENNAI_SUPER_KINGS:
  System.out.println("Chennai Super Kings"); 
  break;

    case RAJASTHAN_ROYALS:
  System.out.println("Rajasthan Royals"); 
  break;

    case ROYAL_CHALLENGERS_BANGALORE:
  System.out.println("Royal Challengers Bangalore"); 
  break;

    case KINGS_XI_PUNJAB:
    System.out.println("Kings XI Punjab"); 
  break;

    case PUNE_WARRIORS:
  System.out.println("Pune Warriors India"); 
  break;

    case DELHI_DAREDEVILS:
  System.out.println("Delhi Daredevils"); 
  break;                 

    default:
    System.out.println("Invalid IPL team choosen");
      }
   }
}






Output of the program :

So you like: Mumbai Indians
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot