java math abs_Java Math类静态双abs(double d)方法与示例

java math abs

数学课静态双ABS(双D) (Math Class static double abs(double d))

  • This method is available in java.lang package.

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

  • This method is used to return the absolute value of the given parameter in the method.

    此方法用于返回方法中给定参数的绝对值。

  • This is a static method so this method is accessible with classname too.

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

  • The return type of this method is depend given argument datatype and here we are passing double datatype in the method that means the return type of this method is double.

    此方法的返回类型取决于给定的参数数据类型,这里我们在方法中传递double数据类型,这意味着该方法的返回类型为double。

  • In this method, we pass only one parameter as an argument in the method of Math class.

    在此方法中,我们仅将一个参数作为参数传递给Math类的方法。

  • This method does not throw any exception.

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

  • This is an overridable method so various versions of this method are available but here we are looking double datatype argument so the following syntax is given below,

    这是一个可重写的方法,因此可以使用该方法的各种版本,但是在这里我们正在寻找double数据类型参数,因此以下语法如下:

Syntax:

句法:

    public static double abs(double d){
    }

Parameter(s):

参数:

double d – a double value whose absolute value to be found.

double d-一个双精度值,其绝对值将被找到。

Return value:

返回值:

The return type of this method is double, returns absolute value as a double.

此方法的返回类型为double ,将绝对值作为double返回。

Note:

注意:

  • If we pass a positive double, it returns the same value.

    如果传递一个正整数,它将返回相同的值。

  • If we pass a negative double, it returns the value without sign i.e. it returns the positive double.

    如果我们传递负双精度数,它将返回不带符号的值,即它将返回正双精度数。

  • If we pass positive zero (0) or negative zero (-0), it returns zero without sign (0).

    如果我们传递正零(0)或负零(-0),则它将返回零而没有符号(0)。

  • If we pass an infinity parameter, it returns the same infinity value without the sign.

    如果我们传递一个无穷大参数,则它将返回相同的无穷大值,但不带符号。

  • If we pass "NaN" (Not A Number), it returns the same i.e. a "NaN".

    如果我们传递“ NaN”(非数字),则返回相同的值,即“ NaN”。

演示abs(double d)方法示例的Java程序 (Java program to demonstrate example of abs(double d) method)

// Java program to demonstrate the example of abs(double d) 
// method of Math class

class AbsDoubleTypeMethod {
    public static void main(String[] args) {
        // We are declaring few variables
        double a = 123.121d;
        double b = -123.121d;
        double c = 0.0d;
        double d = -0.0d;
        double e = 7.70d / 0.0d;
        double f = -7.70d / 0.0d;

        // By using abs(double d) method we will find the 
        // absolute value of given parameter
        System.out.println("The absolute value of a is : " + Math.abs(a));
        System.out.println("The absolute value of b is : " + Math.abs(b));
        System.out.println("The absolute value of c is : " + Math.abs(c));
        System.out.println("The absolute value of d is : " + Math.abs(d));
        System.out.println("The absolute value of e is : " + Math.abs(e));
        System.out.println("The absolute value of f is : " + Math.abs(f));
    }
}

Output

输出量

E:\Programs>javac AbsDoubleTypeMethod.java

E:\Programs>java AbsDoubleTypeMethod
The absolute value of a is : 123.121
The absolute value of b is : 123.121
The absolute value of c is : 0.0
The absolute value of d is : 0.0
The absolute value of e is : Infinity
The absolute value of f is : Infinity


翻译自: https://www.includehelp.com/java/math-class-static-double-abs-double-d-method-with-example.aspx

java math abs

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值