hemlet

do .. while

Feb 1st, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. import javax.swing.*;
  2.  
  3. public class InputDoWhile
  4. {
  5.     static final int TRY = 3;
  6.     public static void main(String[] args)
  7.     {
  8.         String inputString;
  9.         String outputString;
  10.         boolean isGood = false;
  11.         int counter = 0;
  12.        
  13.         //do while
  14.         do
  15.         {
  16.             counter++;
  17.             inputString = JOptionPane.showInputDialog("Enter a four digit code: ");
  18.             if ( inputString.length() == 4)
  19.             {
  20.                 isGood = true;
  21.             }
  22.            
  23.         } while (counter < TRY && !(isGood));//end do while
  24.        
  25.        
  26.         if (isGood)
  27.         {
  28.             outputString = "Welcome your code is " + inputString + "\nwhich is 4 characters long";
  29.             JOptionPane.showMessageDialog(null,outputString, "Correct",JOptionPane.INFORMATION_MESSAGE);
  30.         } else
  31.         {
  32.             outputString = "Do not pass Go! " + inputString + " is not 4 letters " + "\nIt is, in fact, " + inputString.length();
  33.             JOptionPane.showMessageDialog(null,outputString, "Idiot",JOptionPane.WARNING_MESSAGE);
  34.         }
  35.     }
  36. }//class
Advertisement
Add Comment
Please, Sign In to add comment