Switch (aka case) statements are used to select which statements are to be executed depending on a variable's value matching a label. default is used for the else situation. The selection variable can only be int or char datatype.
switch (selection) { case '1':System.out.println("You typed a 1");break; case '2':System.out.println("You typed a 2");break; default:System.out.println("Oops!, that was an invalid entry."); };
No comments:
Post a Comment