java.lang.Math sqrt(double a)

Description :

This java tutorial shows how to use the sqrt(double a) method of Math class under java.lang package. This method returns the square root of the method argument.

Method Syntax :

public static double sqrt(double a)

Parameter Input :

DataType Parameter Description
double a the value which we want to determine square root.

Method Returns :

The sqrt(double a) method simply returns the positive square root of a. Consider the following 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 mathematical square root of the argument value.

Compatibility Version :

Requires Java 1.0 and up

Exception :

N/A

Java Code Example :

This java example source code demonstrates the use of sqrt(double a) method of Math class. Basically we just get the square root of a value.

Sample Output :

Running the sqrt(double a) method example source code of Math class will give you the following output

Exception Scenario :

N/A

Similar Method :

  • N/A

Suggested Reading List :

References :