bobo_bobkata

Untitled

Jun 1st, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1.  public static void main(String[] args) {
  2.         String firtstName = enterName("First");
  3.         String secondName = enterName("Second");
  4.         JOptionPane.showMessageDialog(null, String.format("%s + %s = <Въведи нещо>", firtstName, secondName));
  5.     }
  6.  
  7.     private static String enterName(String type) {
  8.         String name = "";
  9.         boolean isCorrect = false;
  10.         while (!isCorrect) {
  11.             try {
  12.                 name = JOptionPane.showInputDialog(null, "Enter " + type + " Name");
  13.                 Double.parseDouble(name);
  14.                 JOptionPane.showMessageDialog(null, "Try Again");
  15.             } catch (Exception igonred) {
  16.                 JOptionPane.showMessageDialog(null, "Correct - " + name);
  17.                 isCorrect = true;
  18.             }
  19.         }
  20.         return name;
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment