Wednesday, 18 November 2015

Java Tutorial : Java switch statement(Integer)


Click here to watch in Youtube : 
https://www.youtube.com/watch?v=4CdviQPhCtE&list=UUhwKlOVR041tngjerWxVccw

SwitchDemo.java
class SwitchDemo
{
    public static void main(String[] args)
    {

        /*
         * A switch works with the byte, short, char, and int primitive data
         * types. It also works with enumerated types, the String class, and a
         * few special classes that wrap certain primitive types: Character,
         * Byte, Short, and Integer.
         */
        Integer month = 3;
        String monthValue;
        switch (month)
        {
        case 1:
            monthValue = "January";
            break;
        case 2:
            monthValue = "February";
            break;
        case 3:
            monthValue = "March";
            break;
        case 4:
            monthValue = "April";
            break;
        case 5:
            monthValue = "May";
            break;
        case 6:
            monthValue = "June";
            break;
        case 7:
            monthValue = "July";
            break;
        case 8:
            monthValue = "August";
            break;
        case 9:
            monthValue = "September";
            break;
        case 10:
            monthValue = "October";
            break;
        case 11:
            monthValue = "November";
            break;
        case 12:
            monthValue = "December";
            break;
        default:
            monthValue = "Invalid month";
            break;
        }
        System.out.println("Month is : " + monthValue);
    }
}
Output
Month is : March
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/ControlFlowDemoSwitch-Integer-App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/ControlFlowDemoSwitch-Integer-App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/08783475a968761a2cf4b3fc7275842653545b35/BasicJava/ControlFlowDemoSwitch-Integer-App/?at=master

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment