sqrt(): This method is available in the Math class of Java.
Syntax:
double java.lang.Math.sqrt(double a)
This method takes one argument of type double as its parameter. This method returns the correctly rounded positive square root of a double value.
Special cases:
1. If the argument is NaN or less than zero, then the result is NaN.
2. If the argument is positive infinity, then the result is positive infinity.
3. 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 mathematical square root of the argument value.
Parameters: One parameter is required for this method.
a: a value.
Returns: the positive square root of a.If the argument is NaN or less than zero, the result is NaN.
For Example:
Math.sqrt(256) = > It returns 16.0
Approach
Java
public class Sqrt {public static void main(String[] args) {double a = 256;System.out.println(Math.sqrt(a));}}
Output:
16.0
No comments:
Post a Comment