Link to home
Start Free TrialLog in
Avatar of modsiw
modsiw

asked on

sqrt(double) in java.lang.Math cannot be applied to (java.lang.String)

   [javac] C:\FWSrc\src\com\floorwizard\applet\estimation\EW_Util_Spc.java:1089: sqrt(double) in java.lang.Math cannot be applied to (java.lang.String)
    [javac]         adjustLength = (int)Math.floor(Math.sqrt(Math.pow(adjustDisplacement.x,2.0) + Math.pow(adjustDisplacement.y,2.0)));
    [javac]                                            ^

The carrot is under the dot in Math.sqrt .


adjustDisplacement is a ...point2D.Double()
adjustLength is an int


I don't get it...
Avatar of contactkarthi
contactkarthi
Flag of United States of America image

Do a Double.parseDouble()

boefore doing a sqrt
adjustLength = (int)Math.floor(Math.sqrt(Double.parseDouble(Math.pow(adjustDisplacement.x,2.0) + Math.pow(adjustDisplacement.y,2.0))));
Avatar of modsiw
modsiw

ASKER

java.lang.Math.pow(....) returns a double; not a string.
but it takes double NOT string
i didnt notice that
but  sqrt(double) in java.lang.Math cannot be applied to (java.lang.String) means you are trying to do a sqrt on a string instead of double
   public static void main(String[] args)
    {
        int adjustLength = (int) Math.floor(Math.sqrt(Math.pow(2,2.0) + Math.pow(2,2.0)));
        System.out.println(adjustLength);
    }
works fine

dont know why you get that...

try pasting the above in your code in ur ide and see

what ide are you using
Avatar of modsiw

ASKER

From docs; in java.lang.Math:    Neither method is overloaded.

static double       pow(double a, double b)
static double       sqrt(double a)
static double       floor(double a)


>>but  sqrt(double) in java.lang.Math cannot be applied to (java.lang.String) means you are trying to do a sqrt on a string instead of double
Indeed it does, but how did it get the String?

My best guess is that it thinks the + is the concat operator and not add



As far as I can tell, there is no String in that line of code. Hence, why I don't get it.
ASKER CERTIFIED SOLUTION
Avatar of contactkarthi
contactkarthi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of modsiw

ASKER

That works.

This also works
 public static void main(String[] args)
    {
        int adjustLength = (int) Math.floor(Math.sqrt(Math.pow(2.0,2.0) + Math.pow(2.0,2.0)));
        System.out.println(adjustLength);
    }
Avatar of modsiw

ASKER

To be exact: I did it in the start() of an applet and not main. That shouldn't make a difference though.
Avatar of modsiw

ASKER

Figured it out, it was an incorrect import. Two thumbs up for compiler error reporting. =)


import java.awt.geom.Point2D.Double; // This is an incorrect import of an inner class.

import java.awt.geom.Point2D; // This is correct.


Many thanks Contactkarthi.