Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Java sqrt() Method

Java sqrt() Method

Java Number ClassThe Java Number class


The sqrt() method returns the arithmetic square root of the argument.

Syntax



double sqrt(double d)

Parameters

Return Value

Returns the arithmetic square root of the argument.

Example



public class Test{ 

    public static void main(String args[]){

        double x = 11.635;

        double y = 2.76;



        System.out.printf("e 的值为 %.4f%n", Math.E);

        System.out.printf("sqrt(%.3f) 为 %.3f%n", x, Math.sqrt(x));

    }

}

Compile the above program; the output is:



e 的值为 2.7183

sqrt(11.635) 为 3.411


Java Number ClassThe Java Number class