Java Math sqrt() Method

Facebooktwitterredditpinterestlinkedinmailby feather

The sqrt() method of Java Math class returns the accurately rounded positive square root of the specified double value.

Syntax:

public static double sqrt(double a)

Parameters:

The parameter ‘a’ represents the number whose square root is to be determined.

Return Value:

The sqrt() method returns the positive square root of ‘a’.

  • It returns zero with same sign as argument, if the argument is positive or negative zero.
  • It returns infinity with the same sign as the argument, if the argument is infinite.
  • It returns NaN, if the argument is NaN or less than zero.

Example 1:

Output:

Example 2:

Output:

Example 3:

Output:

Example 4:

 

Output:

Example 5:

Output:

Facebooktwitterredditpinterestlinkedinmailby feather