math.pow int_Java Math类静态int abs(int i)方法与示例

math.pow int

数学类静态int abs(int i) (Math Class static int abs(int i))

  • 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 int datatype in the method that means the return type of this method is int.

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

  • 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 int datatype argument so the following syntax is given below,

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

Syntax:

句法:

    public static int abs(int i){
    }

Parameter(s):

参数:

int i – an integer value whose absolute value to be found.

int i –可以找到其绝对值的整数值。

Return value:

返回值:

The return type of this method is int, returns absolute value as an integer.

此方法的返回类型为int ,以整数形式返回绝对值。

Note:

注意:

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

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

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

    如果我们传递一个负整数,它将返回不带符号的值,即它将返回正整数。

  • 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 exception.

    如果我们传递一个无穷大参数,它将返回异常。

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

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

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

// Java program to demonstrate the example of 
// abs(int i) method of Math class

class AbsIntTypeMethod {
    public static void main(String[] args) {
        // We are declaring few variables
        int a = 123121;
        int b = -123121;
        int c = 0;
        int d = -0;
        /*
        int e = 7/0;
        int f = -7/0;
        */

        // By using abs(int i) method we will calculate the 
        // absolute value of given parameter in the method

        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));

        /* 
        // In the below code exception will be thrown 
        // because we are passing infinity
        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 AbsIntTypeMethod.java

E:\Programs>java AbsIntTypeMethod
The absolute value of a is : 123121
The absolute value of b is : 123121
The absolute value of c is : 0
The absolute value of d is : 0


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

math.pow int

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值