Java Data Type Tutorial - Java Math.sqrt(double a)








Syntax

Math.sqrt(double a) has the following syntax.

public static double sqrt(double a)

Example

In the following code shows how to use Math.sqrt(double a) method.

/*  w w w  . j ava  2 s.co m*/


public class Main {

   public static void main(String[] args) {

      double x = 9;
      double y = 25;

      // print the square root of these doubles
      System.out.println("Math.sqrt(" + x + ")=" + Math.sqrt(x));
      System.out.println("Math.sqrt(" + y + ")=" + Math.sqrt(y));

   }
}

The code above generates the following result.