Results 1 to 4 of 4
  1. #1
    xcointoss is offline Member
    Join Date
    Oct 2010
    Posts
    3
    Rep Power
    0

    Default Please look at my java code and tell me what's wrong

    public class Two {

    public static void main(String[] args) {
    int hr = Integer.parseInt (JOptionPane.showInputDialog("Enter hourly rate of pay"));
    int worked = Integer.parseInt (JOptionPane.showInputDialog("Enter number of hours worked"));

    if (worked>=40)
    System.out.println(hr*worked*1.5);
    else
    System.out.println(hr*worked);


    }

    my problem with the code above is that whenever I put decimal numbers, the system stops. For example, 7.5

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    It doesn't just stop, the code will throw a NumberFormatException (note, when you have a question about errors, please inform us of all exceptions or error messages you receive as well as indicate which line causes the exception). If you want to catch and handle the exception, then read the Java tutorials exception section, especially the section on try/catch.

  3. #3
    xcointoss is offline Member
    Join Date
    Oct 2010
    Posts
    3
    Rep Power
    0

    Default

    Fubarable, where can I find thee Java tutorials exception section?
    Can anyone tell me how to fix the NumberFormatException error

  4. #4
    xcointoss is offline Member
    Join Date
    Oct 2010
    Posts
    3
    Rep Power
    0

Similar Threads

  1. What is wrong with my code?!
    By new2java2009 in forum New To Java
    Replies: 2
    Last Post: 04-17-2010, 08:01 PM
  2. what wrong with my java code
    By MAXZZXAM in forum New To Java
    Replies: 3
    Last Post: 11-19-2009, 09:38 AM
  3. Need help! something wrong in my code
    By novak100 in forum New To Java
    Replies: 2
    Last Post: 11-18-2009, 11:59 PM
  4. pls tell wat wrong with my code???
    By low224 in forum New To Java
    Replies: 13
    Last Post: 01-11-2009, 07:40 AM
  5. what is wrong with this code
    By masaka in forum New To Java
    Replies: 5
    Last Post: 04-16-2008, 08:27 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
  •