static int abs(int a)
描述 (Description)
java.lang.StrictMath.abs(int a)方法返回int值的绝对值。 如果参数不是负数,则返回参数。 如果参数为负数,则返回参数的否定。
声明 (Declaration)
以下是java.lang.StrictMath.abs()方法的声明
public static int abs(int a)
参数 (Parameters)
a - 这是要确定其绝对值的参数。
返回值 (Return Value)
此方法返回int值的绝对值。
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.lang.StrictMath.abs()方法的用法。
package com.iowiki;
import java.lang.*;
public class StrictMathDemo {
public static void main(String[] args) {
int i1 = 54 , i2 = -35;
// returns the absolute value of positive int value
int iAbsValue = StrictMath.abs(i1);
System.out.println("absolute value of " + i1 + " = " + iAbsValue);
// returns the absolute value of negative int value
iAbsValue = StrictMath.abs(i2);
System.out.println("absolute value of " + i2 + " = " + iAbsValue);
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
absolute value of 54 = 54
absolute value of -35 = 35