Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2010
    Location
    Warakapola, Sri Lanka
    Posts
    15
    Rep Power
    0

    Exclamation Cannot return Method's value

    Hi,
    I wrote below method. But, I cannot get the computed result as the return value. I know there is going something wrong but I cannot correct it. Please help me correct this.
    Java Code:
    public double convert()
    {
        double result = 0.0;
    
        if(from == "mm")
        {
            if(to == "in")
            {
                result = value * 0.0393701;
            }
        }
    
            return result;
    }
    When I running the code it returns 0.0 as the return value. I need to know how to return "result" calculated in the if condition(result = value * 0.0393701;). There are no problems with other variables in the method.

    Thanks.
    Last edited by darshanaprasad; 09-08-2012 at 08:10 AM.

  2. #2
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default Re: Cannot return Method's value

    do not use "==" to compare two string values

  3. #3
    Join Date
    Apr 2010
    Location
    Warakapola, Sri Lanka
    Posts
    15
    Rep Power
    0

    Default Re: Cannot return Method's value

    got it. worked with equals();
    thanks

Similar Threads

  1. What can a method return?
    By fatabass in forum New To Java
    Replies: 8
    Last Post: 01-29-2012, 02:22 PM
  2. Why is this method return 0
    By africanhacker in forum New To Java
    Replies: 7
    Last Post: 06-30-2011, 06:21 PM
  3. cant return value from a method
    By gedas in forum New To Java
    Replies: 2
    Last Post: 03-23-2011, 07:37 AM
  4. Not able to return the method value
    By dmakshay2002 in forum Advanced Java
    Replies: 11
    Last Post: 05-28-2010, 02:07 PM
  5. Method won't return value
    By footyvino in forum New To Java
    Replies: 2
    Last Post: 03-26-2010, 10:49 AM

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
  •