Results 1 to 2 of 2
  1. #1
    nic21 is offline Member
    Join Date
    Nov 2009
    Posts
    1
    Rep Power
    0

    Default Input JOptionPane

    Dear everyone, anyone can help me to validate this program which only accept number? what i mean is when i type in alphabet it will prompt a message ask us to key in numbers only... anyone could help please... :confused:

    Java Code:
    import javax.swing.*;
    
    public class additiontutor
    {
     public static void main(String args[])
     {
      int number1 = (int)(System.currentTimeMillis() % 10);
      int number2 = (int)(System.currentTimeMillis() * 7 % 10);
    
      String answerString = JOptionPane.showInputDialog
        ("What is " + number1 + " + " + number2 + "?");
    
      int answer = Integer.parseInt(answerString);
      
      JOptionPane.showMessageDialog(null,
        number1 + " + " + number2 + " = " + answer + " is " +
        (number1 + number2 == answer));
     
     }
    }

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    10

Similar Threads

  1. Input technique for unknown lines of input
    By ducreative in forum New To Java
    Replies: 16
    Last Post: 09-23-2009, 10:26 AM
  2. JOptionpane
    By tommyyyy in forum New To Java
    Replies: 2
    Last Post: 03-20-2009, 09:33 AM
  3. JOptionPane
    By whosadork in forum New To Java
    Replies: 2
    Last Post: 10-23-2008, 03:17 AM
  4. JOptionPane - input dialog
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-17-2007, 10:09 AM
  5. how to take input and verify input in Java programs
    By bilal_ali_java in forum Advanced Java
    Replies: 0
    Last Post: 07-21-2007, 09:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •