strictmath_Java StrictMath hypot()方法与示例

strictmath

StrictMath类hypot()方法 (StrictMath Class hypot() method)

  • hypot() method is available in java.lang package.

    hypot()方法在java.lang包中可用。

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

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

  • hypot() method is a static method so it is accessible with the class name and if we try to access the method with the class object then we will not get an error.

    hypot()方法是静态方法,因此可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会收到错误。

  • hypot() method does not throw any exception.

    hypot()方法不会引发任何异常。

Syntax:

句法:

    public static double hypot(double d1 , double d2);

Parameter(s):

参数:

  • double d1 , double d2 – represent the values which are being used to calculate hypot.

    double d1和double d2 –表示用于计算hypot的值。

Return value:

返回值:

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

该方法的返回类型为double-返回给定参数的平方根。

Note:

注意:

  • If we pass infinity in any of the arguments, method returns the positive infinity.

    如果我们在任何参数中传递无穷大,则method返回正无穷大。

  • If we pass NaN in any of the arguments, method returns NaN.

    如果我们在任何参数中传递NaN,则方法返回NaN。

Example:

例:

// Java program to demonstrate the example
// of hypot(double d1 , double d2) method of 
// StrictMath class.

public class Hypot {
    public static void main(String[] args) {
        // variable declarations
        double d1 = 7.0 / 0.0;
        double d2 = 5.0;
        double d3 = 10.0;

        // Display previous value of d1,d2 and d3  
        System.out.println("d1: " + d1);
        System.out.println("d2: " + d2);
        System.out.println("d3: " + d3);

        // Here , we will get (Infinity) because we are 
        // passing parameter whose value is (d2,d1)
        System.out.println("StrictMath.hypot(d2,d1): " + StrictMath.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("StrictMath.hypot(d2,d3): " + StrictMath.hypot(d2, d3));
    }
}

Output

输出量

d1: Infinity
d2: 5.0
d3: 10.0
StrictMath.hypot(d2,d1): Infinity
StrictMath.hypot(d2,d3): 11.180339887498949


翻译自: https://www.includehelp.com/java/strictmath-hypot-method-with-example.aspx

strictmath

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值