/* Loops6.java CIS 160 David Klick 2004-09-17 Demonstrates error checking in a loop */ import javax.swing.JOptionPane; public class Loops6 { public static void main(String[] args) { String strIn; int num; boolean done = false; do { strIn = JOptionPane.showInputDialog("Enter an integer (Q to quit)"); if (strIn == null) { System.out.println("Nothing was entered"); continue; } System.out.println("You entered: " + strIn); if (strIn.equalsIgnoreCase("Q")) { done = true; } else { try { num = Integer.parseInt(strIn); System.out.println("The number is " + num); } catch (NumberFormatException e) { System.out.println("Invalid integer entered"); } } } while (!done); System.exit(0); } }