// // Guess.java: a silly program which forces the user to enter // a number that's either less than 1 or greater than 999 // import javax.swing.*; public class Guess { public static void main(String[] args) { String numstr = JOptionPane.showInputDialog("Enter number: "); if ( numstr == null || numstr.length() == 0 ) JOptionPane.showMessageDialog(null, "You didn't enter anything!"); int num = Integer.parseInt(numstr); while ( 1 <= num && num <= 1000 ) { numstr = JOptionPane.showInputDialog("Sorry, wrong number. Re-enter: "); num = Integer.parseInt(numstr); } if ( num > 1000 ) JOptionPane.showMessageDialog(null, "Final number is large: " + num); else JOptionPane.showMessageDialog(null, "Final number is not positive."); } }