We help IT Professionals succeed at work.

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

on
1,611 Views
[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]                                            ^

The carrot is under the dot in Math.sqrt .

I don't get it...
Comment
Watch Question

## View Solution Only

CERTIFIED EXPERT

Commented:
Do a Double.parseDouble()

boefore doing a sqrt
CERTIFIED EXPERT

Commented:

Commented:
java.lang.Math.pow(....) returns a double; not a string.

Commented:
but it takes double NOT string
CERTIFIED EXPERT

Commented:
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
CERTIFIED EXPERT

Commented:
public static void main(String[] args)
{
int adjustLength = (int) Math.floor(Math.sqrt(Math.pow(2,2.0) + Math.pow(2,2.0)));
}
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

Commented:
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.
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)

Commented:
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)));
}

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

Commented:
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.
Unlock the solution to this question.

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.