Switch case in java
Skip to main content

Switch case in java

how to use switch case in java, switch case in java, java switch,switch statement java,switch program in java, switch case practice questions in java, java switch multiple case,switch case default java, java switch example, switch case in java example, switch case in java syntax, switch case in javascript



Switch case in java

        Switch case in java:- In this tutorial is explain about How to use of switch case in Java with explanation and given example of Java Programming.


Switch Case:- 

           In Java programming switch case is based on selection controling mechanism. Switch case in java multi way branch statement. In switch case you define multiple cases and break is used stop and out from the switch case other statement not execute.


Most Read:- What is Access Modifier in Java? Explain


Switch case syntax:-

switch(expression){

case 1:

// If expression is match to value1 then execute this section

break; 

case 2:

// If expression is match to value2 then execute this section

break;

case n;

// you create a multiple case 

break;

default:

break;

}

Switch case example:-

    In this example we use a switch case. There is defined a integer type value mValue=2 that defind integer type value passed into the switch case. When switch case is call then that the case first but its not match then move to the second case there its match and print the output. program out from the switch case because use break keyword and next case is not execute. If no case execute the execute the default case.

class SwitchcaseExample{

      public static void main(String[] args){

      int mValue=2;

       switch(mValue){

          case 1: System.out.println("One");

           break;

          case 2: System.out.println("Two");

            break;

          case 3: System.out.println("Three");

          break;

           default:

            System.out.println("No case execute");

           break;

      }

}

}


Post a Comment

0 Comments