modsiw
asked on
sqrt(double) in java.lang.Math cannot be applied to (java.lang.String)
[javac] C:\FWSrc\src\com\floorwiza rd\applet\ estimation \EW_Util_S pc.java:10 89: sqrt(double) in java.lang.Math cannot be applied to (java.lang.String)
[javac] adjustLength = (int)Math.floor(Math.sqrt( Math.pow(a djustDispl acement.x, 2.0) + Math.pow(adjustDisplacemen t.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...
[javac] adjustLength = (int)Math.floor(Math.sqrt(
[javac] ^
The carrot is under the dot in Math.sqrt .
adjustDisplacement is a ...point2D.Double()
adjustLength is an int
I don't get it...
adjustLength = (int)Math.floor(Math.sqrt( Double.par seDouble(M ath.pow(ad justDispla cement.x,2 .0) + Math.pow(adjustDisplacemen t.y,2.0))) );
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
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(adjustL ength);
}
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
{
int adjustLength = (int) Math.floor(Math.sqrt(Math.
System.out.println(adjustL
}
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
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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(adjustL ength);
}
This also works
public static void main(String[] args)
{
int adjustLength = (int) Math.floor(Math.sqrt(Math.
System.out.println(adjustL
}
ASKER
To be exact: I did it in the start() of an applet and not main. That shouldn't make a difference though.
ASKER
Figured it out, it was an incorrect import. Two thumbs up for compiler error reporting. =)
import java.awt.geom.Point2D.Doub le; // This is an incorrect import of an inner class.
import java.awt.geom.Point2D; // This is correct.
Many thanks Contactkarthi.
import java.awt.geom.Point2D.Doub
import java.awt.geom.Point2D; // This is correct.
Many thanks Contactkarthi.
boefore doing a sqrt