Groovy - sqrt()

该方法返回参数的平方根。


语法

double sqrt(double d)

参数

d - 任何原始数据类型。


返回值

此方法返回参数的平方根。


示例

以下是该方法的用法示例 −

class Example { 
   static void main(String[] args) { 
      double x = 11.635; 
      double y = 2.76; 
	  
      System.out.printf("The value of e is %.4f%n", Math.E); 
      System.out.printf("sqrt(%.3f) is %.3f%n", x, Math.sqrt(x)); 
   } 
}

当我们运行上面的程序时,会得到下面的结果 −

The value of e is 2.7183 
sqrt(11.635) is 3.411

❮ Groovy 数字