Blog Introductions
In this blog contains tutorials about HTML Tutorials, Python Tutorials, CSS Tutorials, How to, PHP Tutorials, Java Tutorials, C++ Tutorials, Tutorials, Examples, Source code,Learning,
Tips and Software development services. Java Switch control flow | Java tutorials Bestitworriors
Java Switch control flow
Java Switch control flow | Java tutorials Bestitworriors - Switch execute one block from many blocks.Switch is usefull when you have multiple condation to check and execute the result base on condations.Swich use case statement ot chech the condation . We pass parameter to the switch.If none of case match in switch then execute the default block.Switch is usefull and save time when you have multiple condations rather then switch multiple if-else use lot of time more line of codes and time consuming process.
Some Key Points of Java Switch
- Switch execute one block form many blocks
- In switch we use case statement to check the condation
- Switch save time and consume less lines of codes
- We pass parameter to the switch
- If none of condation is match then execute the default block
- Switch is usefull when multiple if-else occure
Code
public
class switches {
public static void main(String[] args) {
int months = 4;
switch (months) {
case 1:
System.out.println("January");
break;
case
2:
System.out.println("Feburary");
break;
case
3:
System.out.println("March");
break;
case
4:
System.out.println("April");
break;
case
5:
System.out.println("May");
break;
case
6:
System.out.println("June");
break;
case
7:
System.out.println("July");
break;
}
}
}
0 Comments