wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes sqrt compile error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "sqrt compile error" Watch "sqrt compile error" New topic
Author

sqrt compile error

Stephanie Dears
Ranch Hand

Joined: May 26, 2005
Posts: 43
Ken, Jim...I'M BAAAAAAACK!!

I hope this next assignment is better than the last. This one is a hummer...robots...my mind just spins typing the word.

To begin...I haven't even gotten into the meat of the multiple classes involved.

I have a class called Coordinates.

Inside I have a method:



I get "cannot find symbol".

What do you think?

Steph
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18529
    
  40

Are the x, y, and distance variables defined anywhere?


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18529
    
  40

Ohhh... forgot... is the sqrt() method defined anywhere?
diels pei
Greenhorn

Joined: Dec 05, 2005
Posts: 1
you can use Math.sqrt(),
public double calculateDistanceToOrigin()
{
distance = Math.sqrt(x*x + y *y);
return distance ;
}
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Hi Steph.

[Steph]: I get "cannot find symbol".

And, immediately after these words, it should tell you which symbol, on which line of the file, it's talking about. This would be useful information to know.


"I'm not back." - Bill Harding, Twister
Stephanie Dears
Ranch Hand

Joined: May 26, 2005
Posts: 43
Jim,

I knew you would be glad to hear from me.

Diels mentioned using Math.sqrt...I did that and received no error. On to the next step. We can only hope.

Thanks Jim and Diels.

Henry,

Yes, the x, y, and distance were defined. How do you define a sqrt? I looked in my books and on the net and couldn't find anything.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18529
    
  40

Originally posted by Stephanie Dears:

Yes, the x, y, and distance were defined. How do you define a sqrt? I looked in my books and on the net and couldn't find anything.


Didn't you just mentioned that you are going to use the method that is defined in the Math class?

Henry
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[Steph]: How do you define a sqrt?

Probably you just want to use Math.sqrt() as Diels suggested. It's possible to define your own, but most likely that's well outside the scope of this problem. If you really want to know the details, you can google "Newton's method" and "square root" together to get a lot of discussion of the most common technique. But only do that if you're sure you can't just use a pre-existing method like Math.sqrt().
[ December 05, 2005: Message edited by: Jim Yingst ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sqrt compile error
 
Similar Threads
HELP!
Reading data from files and other classes
[easy]Find the number
set pixel in frame
HELP!