Results 1 to 6 of 6
  1. #1
    flecdorbee is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Question What is wrong with this program!?

    PLEASE HELP!


    {
    //-----------------------------------------------------------------
    // Determines if the value input by the user is even or odd.
    // Uses multiple dialog boxes for user interaction.
    //-----------------------------------------------------------------
    public static void main (String[] args)
    {
    String numStr, result;
    int num, again;

    do
    {
    numStr = JOptionPane.showInputDialog ("Enter an integer: ");

    num = Integer.parseInt(numStr);

    result = "That number is " + ((num%2 == 0) ? "even" : "odd");

    JOptionPane.showMessageDialog (null, result);

    again = JOptionPane.showConfirmDialog (null, "Do Another?");
    }
    while (again == JOptionPane.YES_OPTION);
    }
    }
    :confused::confused::confused::confused::confused: :confused::confused::confused::confused::confused:

    im using the current version of Dr java with Eclipse compiler 0.A48and Java

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    There are bits of the program missing. It would help if we could see the whole thing. (When posting code use the "code" tags: you put [code] at the start of the code and [/code] at the end. That way the formatting is preserved.)

    Basically it is up to *you* to say what is wrong with the program. Does it compile? If not, and you can't understand the compiler messages, post them.

    Does it compile but shows unexpected or unwanted behaviour (including runtime exceptions) when you run it? If so, describe that behaviour.

  3. #3
    flecdorbee is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default

    Java Code:
    import javax.swing.JOptionPane;
    public class EvenOdd
    {
       //-----------------------------------------------------------------
       //  Determines if the value input by the user is even or odd.
       //  Uses multiple dialog boxes for user interaction.
       //-----------------------------------------------------------------
       public static void main (String[] args)
       {
          String numStr, result;
          int num, again;
    
          do 
          {
             numStr = JOptionPane.showInputDialog ("Enter an integer: ");
    
             num = Integer.parseInt(numStr);
    
             result = "That number is " + ((num%2 == 0) ? "even" : "odd");
    
             JOptionPane.showMessageDialog (null, result);
    
             again = JOptionPane.showConfirmDialog (null, "Do Another?");
          }
          while (again == JOptionPane.YES_OPTION);
       }
    }
    When i try to compile it, it says all the defining characters ("[", "(", etc) and the "void" is an error and im at a complete loss

  4. #4
    flecdorbee is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default

    holy crap! as soon as i posted last, it started running >_< thanks for your help bro, appreciate it!(BTW u have a beautiful country)

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    it started running >_<

    A simple typo with a bracket will confuse the compiler mightily! Anyway, I'm glad it's doing what you want.

    Not so beautiful for the folks in Christchurch at the moment... (I passed through there in mid January and on both days I was there there were eathquakes: apparently they have been quite common since last October.)

  6. #6
    flecdorbee is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default

    that sucks! i went there with the people to people student ambassador organization in '05.

Similar Threads

  1. Whats wrong with my program?
    By jwb4291 in forum New To Java
    Replies: 7
    Last Post: 12-12-2010, 05:40 AM
  2. what the wrong in my program ><
    By MSs.Java in forum New To Java
    Replies: 4
    Last Post: 05-03-2010, 02:28 PM
  3. Wrong Order in Program Run
    By HeatR216 in forum New To Java
    Replies: 0
    Last Post: 03-25-2010, 09:41 PM
  4. What's wrong in my program...?
    By Annatar in forum Java Software
    Replies: 3
    Last Post: 10-31-2008, 07:03 AM
  5. what is wrong with this program ?
    By Poor Bee in forum New To Java
    Replies: 1
    Last Post: 05-07-2008, 08:23 PM

Tags for this Thread

Posting Permissions

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