Java.lang.StrictMath 类

java.lang.StrictMath.hypot() 方法返回两个参数平方和的平方根,即 sqrt (x2 +y2)。在特殊情况下,它返回以下内容:

  • 如果任一参数是无限的,则结果为正无穷。
  • 如果任一参数为 NaN 并且两个参数都不是无限的,则结果为 NaN。

语法

public static double hypot(double x, double y)

参数

x 指定一个值。
y 指定一个值。

返回值

返回 sqrt(x2 +y2)。

异常

不适用。

示例:

在下面的示例中,hypot() 方法返回 sqrt(x2 +y2)。

import java.lang.*;

public class MyClass {
 public static void main(String[] args) {
  System.out.println(StrictMath.hypot(3, 4));   
  System.out.println(StrictMath.hypot(5, 12));
  System.out.println(StrictMath.hypot(8, 15));     
 }
}

上述代码的输出将是:

5.0
13.0
17.0