Code:import java.io.*; import javax.swing.JOptionPane; public class MyType { public static void main(String[] args) { String strChoice, strTryString, strTryInt, strTryDouble; int choice, tryInt; double tryDouble; boolean done = false; while(!done) { try { String message = "What's My Type?" + "\n\n1) String\n2) Integer\n3) Double\n4) Quit the program\n\n"; choice = Integer.parseInt(strChoice); if (choice<1 || choice>3) throw new NumberFormatException(); else done = true; } switch(choice) { case 1: System.out.println("You are correct"); break; case 2: choice = Integer.parseInt(strtryInt); case 3: choice = Double.parseDouble(strtryDouble); case 4: done = true; } return choice; catch(numberFormatException e) { outputLabel.setText("Try Again."); } } } }




Reply With Quote