Results 1 to 2 of 2
  1. #1
    christopherx is offline Member
    Join Date
    Oct 2011
    Posts
    92
    Rep Power
    0

    Default function returning 0 for no reason.

    Java Code:
    private int parseTemp(String inputTemp)
    {
        if((inputTemp.matches("[0-9]+c")) || (inputTemp.matches("[0-9]+C")))
        {
            int newTemp = Integer.parseInt(inputTemp.substring(0,inputTemp.length() - 1));
            return newTemp;
        }
        else if((inputTemp.matches("[0-9]+f")) || (inputTemp.matches("[0-9]+F")))
        {
            // This section from here:
            int newTemp = Integer.parseInt(inputTemp.substring(0,inputTemp.length() - 1));
            newTemp = (newTemp - 32) * (5/9);
            return newTemp;
            // : to here, returns 0 for some odd reason.
        }
        else
        {
            System.out.println("Sorry. Given string was not in the correct format.");
            return 0;
        }
    }
    Hey guys. Basically, i'm trying to convert from celsius to farenheit. Now, This function above is getting the correct format for input, and it isn't throwing an error message so I don't really understand where I'm going wrong with this. Basically, in the highlighted area, it just returns 0, without any mathematical justification. The ifstatement above it works fine though. Can you guys see anything wrong with it?

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

Similar Threads

  1. Function call returning array of objects
    By ShitalJain in forum New To Java
    Replies: 4
    Last Post: 06-25-2011, 09:39 AM
  2. Best reason to not go to school ever
    By Zack in forum Forum Lobby
    Replies: 5
    Last Post: 11-28-2010, 04:09 AM
  3. Need a reason for output
    By Hemant16 in forum Threads and Synchronization
    Replies: 3
    Last Post: 09-26-2010, 10:05 AM
  4. Getting errors for some reason
    By Swarvy in forum New To Java
    Replies: 7
    Last Post: 09-30-2008, 02:45 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
  •