
#19 Known is a Drop! Switch Statement in JAVA
The switch Statement : Unlike if-then and if-then-else statements, the switch statement can have a number of possible execution paths. The body of a switch statement is known as a switch block. A statement in the switch block can be labeled with one or more case or default labels. The switch statement evaluates its expression, then executes all statements that follow the matching case label. Classic Switch (Java 1.0 – 6) Uses switch(expression) and case value: blocks. Must use break to prevent fall-through. Only supports int, byte, short, char (no String yet). public class SwitchCase { int orderStastusCode = 2 ; public static void main ( String [] args ) { SwitchCase sc = new SwitchCase (); sc . menu ( sc . orderStastusCode ); } private void menu ( int orderStastusCode ) { switch ( orderStastusCode ) { case 1 : System . out . println ( "You have ordered idli" ); System . out . println ( "Enjoy your idlii" ); break ; case 2 : System . out . println ( "You have ordered Briyani" ); System
Continue reading on Dev.to Tutorial
Opens in a new tab




