Sunday, March 16, 2014

Simple Switch Case in Java | Example | Source code

Written by Pranshu Bajpai |  | LinkedIn

Source Code



package DICAss;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.io.*;
/**
 *
 * @author Pranshu
 */
public class DICAss6_SwitchCase {
    public static void main(String[] args){
        
        int ch;
        
        BufferedReader BRObj = new BufferedReader
                (new InputStreamReader(System.in));
        
        System.out.print("Give Input : ");
        
        try{
            ch = Integer.parseInt(BRObj.readLine());
            
            switch (ch)
                    {
                        case 1:
                            System.out.println("Jan");
                        break;
                       
                        case 2:
                            System.out.println("Feb");
                        break;
                            
                        case 3:
                            System.out.println("Mar");
                        break;
                            
                        case 4:
                            System.out.println("Apr");
                        break;
                            
                        case 5:
                            System.out.println("May");
                        break;
                        
                        case 6:
                            System.out.println("Jun");
                        break;
                            
                        case 7:
                            System.out.println("July");
                        break;
                        
                        case 8:
                            System.out.println("Aug");
                        break;
                        
                        case 9:
                            System.out.println("Sept");
                        break;
                            
                        case 10:
                            System.out.println("Oct");
                        break;
                            
                        case 11:
                            System.out.println("Nov");
                        break;
                            
                        case 12:
                            System.out.println("Dec");
                        break;
                          
                        default:
                            System.out.println("Wrong Choice!!!");
                        
                    }
        }
        catch(Exception err){
            System.out.println("Error : " + err);
        }
    }
}

No comments:

Post a Comment