js math.hypot_Java Math类静态double hypot(double d1,double d2)与示例

js math.hypot

数学类静态double hypot(double d1,double d2) (Math Class static double hypot(double d1, double d2))

  • This method is available in java.lang package.

    此方法在java.lang包中可用。

  • This method is used to return the square root of (square(d1)+ square(d2)) without any intermediate operations or in other words it returns the sqrt(square(d1)+ square(d2)).

    此方法用于返回(square(d1)+ square(d2))的平方根,而无需任何中间操作,换句话说,它返回sqrt(square(d1)+ square(d2))。

  • This is a static method so it is accessible with the class name too.

    这是一个静态方法,因此也可以使用类名进行访问。

  • The return type of this method is double that means it returns the square root of the given argument.

    此方法的返回类型为double,这意味着它将返回给定参数的平方根。

  • In this method, we pass two parameters as arguments and both of the parameters are of double type.

    在此方法中,我们将两个参数作为参数传递,并且两个参数均为double类型。

  • This method does not throw any exception.

    此方法不会引发任何异常。

Syntax:

句法:

    public static double hypot(double d1 , double d2){
    }

Parameter(s): d1 and d2 – both are the double values which will be used to find the square root of (d1*d1 + d2*d2).

参数: d1和d2 –均为双精度值,将用于查找(d1 * d1 + d2 * d2)的平方根。

Return value:

返回值:

The return type of this method is double, it returns the Euclidean norm i.e. square root of (d12+d22).

此方法的返回类型为double ,它返回欧几里得范数,即(d1 2 + d2 2 )的平方根。

Note:

注意:

  • If we pass an infinity in any of the given arguments, it returns the infinity.

    如果我们在任何给定参数中传递无穷大,它将返回无穷大。

  • If we pass "NaN" in any of the given arguments, it returns the "NaN".

    如果我们在任何给定参数中传递“ NaN”,它将返回“ NaN”。

Java程序演示hypot(double d1,double d2)方法的示例 (Java program to demonstrate example of hypot(double d1, double d2) method)

// Java program to demonstrate the example of 
// hypot(double d1 , double d2) method of Math Class

public class HypotMethod {
    public static void main(String[] args) {
        // Here we are declaring few variables
        double d1 = 7.0 / 0.0;
        double d2 = 5.0;
        double d3 = 10.0;

        // displaying the values
        System.out.println("d1: " + d1);
        System.out.println("d2: " + d2);
        System.out.println("d3: " + d3);

        // Here , we will get (NaN) because we are passing 
        // parameter whose value is (d2,d1)
        System.out.println("Math.hypot(d2,d1): " + Math.hypot(d2, d1));

        // Here , we will get (sqrt(sq(d2)+sq(d3))) because 
        // we are passing parameter whose value is (d2,d3)
        System.out.println("Math.hypot(d2,d3): " + Math.hypot(d2, d3));
    }
}

Output

输出量

E:\Programs>javac HypotMethod.java

E:\Programs>java HypotMethod
d1: Infinity
d2: 5.0
d3: 10.0
Math.hypot(d2,d1): Infinity
Math.hypot(d2,d3): 11.180339887498949


翻译自: https://www.includehelp.com/java/math-class-static-double-hypot-double-d1-double-d2-with-example.aspx

js math.hypot

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值