The Math.sqrt() method returns the positive, properly rounded square root of a double-type value.


Math.sqrt(double num)

The return type of the .sqrt() method is a double. The data type of the num parameter is also a double. However, if a decimal is not provided, num will still be treated like a double-type.

Some edge cases for the .sqrt() method include the following:

  • If num is less than zero or it is not a numeric type (NaN), then NaN is returned.
  • If num is positive infinity (Double.POSITIVE_INFINITY), then Infinity is returned.


The following example showcases the .sqrt() method being applied to two variables:

public class Check {
public static void main(String args[]) {
double x = 64.0;
double y = 49.0;

This results in the following output:



Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn Java on Codecademy