How can I find the square root of something?

In my program I need to be able to find the square root of something. I know I could use a while statement, but the user is going to be entering a few numbers in so the square root isnt always going to come out exact, it is going to come out in decimals as a float.

I am using the quad formula, and I made the stuff under the square root a variable to make it a tad easier for a different part of my program. But I cant figure out how to find out the square root of something.

[490 byte] By [punchout] at [2007-9-30 23:28:57]
# 1
Math.sqrt();if you have to make your own algorithm, GOOGLE IS YOUR FRIEND!
Adeodatus at 2007-7-7 14:31:58 > top of Java-index,Security,Event Handling...
# 2

Ok I knew that, I dont know why I forgot - But thanks a lot

But not how can I make sure the number is positive before I square it (it won't square negative numbers)

So say I have the variable 'answer' and I need to square its value which is sometimes positive and sometimes negative according to the user. How can I make sure its always positive?

answer = +answer

lol that doesnt work, so what is it

Much Thanks

punchout at 2007-7-7 14:31:58 > top of Java-index,Security,Event Handling...
# 3
Math.abs()Really, you should ask the docs these questions, not me.
Adeodatus at 2007-7-7 14:31:58 > top of Java-index,Security,Event Handling...
# 4
I believe there's an abs method in the Math class. Or you could test if (num < 0)
jverd at 2007-7-7 14:31:58 > top of Java-index,Security,Event Handling...
# 5
> answer = +answerNot sure if that's even legal in Java, but if it is, you should realize that it's identical to answer = answer
jverd at 2007-7-7 14:31:58 > top of Java-index,Security,Event Handling...
# 6
and, not that this helps with homework or developing your own algorithm, there's also a sqrt method in the Math class.
tsith at 2007-7-7 14:31:58 > top of Java-index,Security,Event Handling...