An Introduction to Math.sqrt() - Java's method for getting square roots

Math.sqrt() Function in Java

Description: Math.sqrt() method returns the square root value of the primitive data type. If a number is less than zero, it will return NaN.

Signature:

double sqrt(double d)

Parameters:

Contains primitive data type.

Return Value:

Returns the square root of argument.

Example:

public class Math {

 public static void main(String[] args) {

  double a = Math.sqrt(9); //calculates square root of 9
  double b = Math.sqrt(2456.7); //calculates square root of 2456.7
  double c = Math.sqrt(-4568); //calculates square root of -4568

  System.out.println("Math Square root value :" + a);
  System.out.println("Math Square root value :" + b);
  System.out.println("Math Square root value :" + c);

 }

}

Output:

Math Square root value: 3.0
Math Square root value: 49.565108695532984
Math Square root value: NaN

:rocket: Run Code

Source: Math.sqrt()

Nice to see here a Java section…

By the way, I tried to run the code, but not worked until I changed the class name to Main.