Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- public class InputDoWhile
- {
- static final int TRY = 3;
- public static void main(String[] args)
- {
- String inputString;
- String outputString;
- boolean isGood = false;
- int counter = 0;
- //do while
- do
- {
- counter++;
- inputString = JOptionPane.showInputDialog("Enter a four digit code: ");
- if ( inputString.length() == 4)
- {
- isGood = true;
- }
- } while (counter < TRY && !(isGood));//end do while
- if (isGood)
- {
- outputString = "Welcome your code is " + inputString + "\nwhich is 4 characters long";
- JOptionPane.showMessageDialog(null,outputString, "Correct",JOptionPane.INFORMATION_MESSAGE);
- } else
- {
- outputString = "Do not pass Go! " + inputString + " is not 4 letters " + "\nIt is, in fact, " + inputString.length();
- JOptionPane.showMessageDialog(null,outputString, "Idiot",JOptionPane.WARNING_MESSAGE);
- }
- }
- }//class
Advertisement
Add Comment
Please, Sign In to add comment