Java.lang.StrictMath.sqrt() 方法
描述
java.lang.StrictMath.sqrt() 方法返回双精度值的正确舍入正平方根。它包括这些情况 −
- 如果参数为 NaN 或小于零,则结果为 NaN。
- 如果参数为正无穷大,则结果为正无穷大。
- 如果参数为正零或负零,则结果与参数相同。
否则,结果是最接近参数值的真正数学平方根的双精度值。
声明
以下是 java.lang.StrictMath.sqrt() 方法的声明。
public static double sqrt(double a)
参数
a − 这是要使用的值。
返回值
此方法返回 a 的正平方根。
异常
NA
示例
下面的例子展示了 java.lang.StrictMath.sqrt() 方法的使用。
package com.tutorialspoint;
import java.lang.*;
public class StrictMathDemo {
public static void main(String[] args) {
double d1 = 121 , d2 = -729, d3 = 0.0;
// returns the positive square root of a double value.
double sqrtValue = StrictMath.sqrt(d1);
System.out.println("square root of " + d1 + " = " + sqrtValue);
sqrtValue = StrictMath.sqrt(d2);
System.out.println("square root of " + d2 + " = " + sqrtValue);
sqrtValue = StrictMath.sqrt(d3);
System.out.println("square root of " + d3 + " = " + sqrtValue);
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
square root of 121.0 = 11.0 square root of -729.0 = NaN square root of 0.0 = 0.0

