Wednesday, 18 November 2015

Java Tutorial : Java switch statement(multiple case)


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

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

        int month = 5;
        int numDays = 0;

        switch (month)
        {

        /*
         * Shows how a statement can have multiple case labels
         */

        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            numDays = 31;
            break;
        case 4:
        case 6:
        case 9:
        case 11:
            numDays = 30;
            break;
        case 2:
            numDays = 28;
            break;
        default:
            System.out.println("Invalid month.");
            break;
        }
        System.out.println("Number of Days = " + numDays);

    }
}
Output
Number of Days = 31

Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/ControlFlowDemoSwitch-MultiCase-App.zip?attredirects=0&d=1

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/08783475a968761a2cf4b3fc7275842653545b35/BasicJava/ControlFlowDemoSwitch-MultiCase-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

    Google+ Followers

    Google+ Badge