Posts

Showing posts with the label switch statement

switch statement

The Java switch statement executes one statement from multiple conditions. It is like if-else-if ladder statement. switch statement Syntax switch(expression){ case value1: //code to be executed; break; //optional case value2: //code to be executed; break; //optional ...... default: code to be executed if all cases are not matched; } Program public class switch_example { public static void main(String args[]) { int age = 20; switch(age) { case 10: System.out.println("You are child."); break; case 20: System.out.println("You are teenager."); break; case 30: System.out.println("You are matured."); break; case 40: System.out.println("You are old."); break; default: ...