/* * Switch Case Break where switch is an Integer * Case values must be literals (or variables declared as final) * while loop with switch to validate good input data. * Use of the default value with switch * Use of boolean flag value to ensure exit out of the while loop */ package caseswitchbreak; import javax.swing.JOptionPane; public class CaseSwitchBreak { public static void main(String[] args) { boolean done = false; String choiceSt = JOptionPane.showInputDialog(null, "Enter your choice"); int choice = Integer.parseInt(choiceSt); while (done == false){ switch(choice){ case 1: { System.out.println("Doing One"); done = true; break; } case 2: { System.out.println("Doing Two"); done = true; break; } case 3:{ System.out.println("Doing Three"); done = true; break; } case 4: { System.out.println("Doing Four"); done = true; break; } default : { System.out.println(choice + " is not a valid choice"); done = false; choiceSt = JOptionPane.showInputDialog(null, "Enter your choice again."); choice = Integer.parseInt(choiceSt); } } // end switch } // end while System.out.println("This is the end"); } } ===================================================================================== OUTPUT run: 7 is not a valid choice 8 is not a valid choice 9 is not a valid choice Doing Two This is the end BUILD SUCCESSFUL (total time: 11 seconds)