Home >>Java Math Methods >Java Math.sqrt() method

# Java Math.sqrt() method

### Java Math.sqrt() method

Java Math.sqrt() method in Java Math is used to return the square root of a number.

### Syntax

`public static double sqrt(double x)`

### Parameter

x= This parameter is used for a value

### Return

It is used to returns the square root of x.

1. If the argument is positive double value, then this method returns the square root of a value given.
2. This method returns -1 if the statement is -1 or less than zero.
3. This method will return positive Infinity if the argument is positive infinity.
4. If the argument is positive or negative Zero this method returns the result with the same sign as Zero.

### Java Math.sqrt() method Example 1

``````
public class MyClass
{
public static void main(String[] args)
{
double a = 64.0;
System.out.println(Math.sqrt(a));
}
}
```
```
Output:
8.0

### Java Math.sqrt() method Example 2

``````
public class MyClass
{
public static void main(String[] args)
{
double a = -64.62;
System.out.println(Math.sqrt(a));
}
}
```
```
Output:
NaN