Pin It

Program demonstrating Switch statement working in Java

Program to demonstrate working of Switch statements in Java



package com.hubberspot.examples;

import java.util.Scanner;

public class SwitchTest {

 
    public static void main(String[] args) {
      
     Scanner scanner = new Scanner(System.in);
      
        System.out.println("This seasons IPL Teams : ");
 System.out.println("***********************************");         
        System.out.println("1. Deccan Chargers");
        System.out.println("2. Kolkata Night Riders");
        System.out.println("3. Mumbai Indians");
        System.out.println("4. Chennai Super Kings");
        System.out.println("5. Rajasthan Royals");
        System.out.println("6. Royal Challengers Bangalore");
        System.out.println("7. Kings XI Punjab");
        System.out.println("8. Pune Warriors India");
        System.out.println("9. Delhi Daredevils");
        System.out.print("");
        System.out.println("***********************************");
        System.out.print("Please choose your favorite IPL team: ");
  
        int team = scanner.nextInt();    
  
        System.out.print("So you like: ");
         
        switch (team) {
            case 1:
                System.out.println("Deccan Chargers"); 
                break;
            case 2:
                System.out.println("Kolkata Night Riders"); 
                break;
            case 3:
                System.out.println("Mumbai Indians"); 
                break;
            case 4:
                System.out.println("Chennai Super Kings"); 
                break;
            case 5:
                System.out.println("Rajasthan Royals"); 
                break;
            case 6:
                System.out.println("Royal Challengers Bangalore"); 
                break;
            case 7:
                System.out.println("Kings XI Punjab"); 
                break;
            case 8:
                System.out.println("Pune Warriors India"); 
                break;
            case 9:
             System.out.println("Delhi Daredevils"); 
             break;                 
            default:
                System.out.println("Invalid IPL team choosen");
        }
    }
}





Output of the program :



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