Java.lang.Math.hypot() 方法
描述
java.lang.Math.hypot(double x, double y) 返回 sqrt(x2 +y2) 没有中间溢出或下溢 . 特别案例:
如果任一参数为无穷大,则结果为正无穷大。
如果任一参数为 NaN,且任一参数均不是无限大,则结果为 NaN。
声明
以下是 java.lang.Math.hypot() 方法的声明。
public static double hypot(double x, double y)
参数
x − 一个值
y − 一个值
返回值
此方法返回 sqrt(x2 +y2) 没有中间溢出或下溢
异常
NA
示例
下面的例子展示了 lang.Math.hypot() 方法的使用。
package com.tutorialspoint;
import java.lang.*;
public class MathDemo {
public static void main(String[] args) {
// get two double numbers
double x = 60984.1;
double y = -497.99;
// call hypot and print the result
System.out.println("Math.hypot(" + x + "," + y + ")=" + Math.hypot(x, y));
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
Math.hypot(60984.1, -497.99)=60986.133234122164

