Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

sq Root

  Asked By: Robert    Date: Aug 12    Category: Java    Views: 562
  

Is there any function in java that calculates square root?
Thanks.

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Kay Rodriguez     Answered On: Aug 12

sqrt
public static double sqrt(double a)

Returns the correctly rounded positive square root  of a double value. Special
cases:

· If the argument is NaN or less than zero, then the result is NaN.
· If the argument is positive infinity, then the result is positive infinity.
· If the argument is positive zero or negative zero, then the result is the same
as the argument.

Otherwise, the result is the double value closest to the true mathetmatical
square root of the argument value.

Parameters:
a - a double

 
Answer #2    Answered By: Paul Brooks     Answered On: Aug 12

public class sqrt
{
public static void main(String args[])
{
System.out.println(java.lang.Math.sqrt(4));

}
}

 
Answer #3    Answered By: Sheryl Morgan     Answered On: Aug 12

to get the square root  of a number,let's say 9 (w/c is 3) try this
one in your main method:

double anyNumber=9;
System.out.println("Square root: " + Math.sqrt(anyNumber));

 
Didn't find what you were looking for? Find more on sq Root Or get search suggestion and latest updates.




Tagged: