Results 1 to 5 of 5

Thread: Please Help!!!

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Posts
    2

    Question Please Help!!!

    I have just started studying java and am working on our first class assignment. It's just a simple program that takes two integers and tell which one is larger or if they're equal. What I want to know is what I need to put in the program to tell if they just pressed enter without entering any numbers. Because if they did do this the program just crashes. I think it's some sort of null thing, but i can't figure it out. Here's the code so far:
    import javax.swing.JOptionPane;

    public class Java12 {
    public static void main( String args[] )
    {
    // Create the variables

    String firstNumber,
    secondNumber;
    int number1 = 0,
    number2 = 0,
    largest = 0;

    firstNumber =
    JOptionPane.showInputDialog(" Enter the first integer");

    secondNumber =
    JOptionPane.showInputDialog(" Enter the second integer");


    number1 = Integer.parseInt( firstNumber );
    number2 = Integer.parseInt( secondNumber );


    // check to see which number is larger, smaller or equal

    if (number1 > number2)
    JOptionPane.showMessageDialog( null," " + number1 + " is larger " , "Results", JOptionPane.PLAIN_MESSAGE );
    else

    if (number2 > number1)
    JOptionPane.showMessageDialog( null," " + number2 + " is larger " , "Results", JOptionPane.PLAIN_MESSAGE );
    else

    if (number2 == number1)
    JOptionPane.showMessageDialog( null, "These numbers are equal ", "Results", JOptionPane.PLAIN_MESSAGE );



    System.exit( 0 );

    }
    }
    Last edited by Stussy_3; Jan 24th, 2002 at 01:55 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width