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:-
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;
}
}
}
0 Comments
Hello Friends, Please comment and share and do not write spam messages