W elcome back to my blog!!! In my previous post you learned about if , nested ifs and else-if-else in Java. In this post you will learn about switch . What is a switch? In Java, a switch is a multiway branch statement. General form of a switch: switch(expression) { case value1: statement; break; case value2: statement; break; . . . . . . default: statement; break; } The expression must be the type of int , byte , short or char . Duplicate case values are not allowed. The switch statement works like this: the value of the expression is compared with each of the literal values in the case statements. If a match is found, the code sequence following the case statement is executed. If none of the constants matches the value of the expressions, then the default statement is executed. however, the default statement is optional. If no case matches and no default is present, then no further action is taken. The break statement i
Hello to all the technology lovers! If you love programming and tech stuff, you've come to the right place! I look forward to sharing accurate and more and more tech knowledge with you! If you like my post, kindly keep me motivated by sharing and subscribing to my Blog.