Java Math abs() 方法
实例
返回不同数字的绝对 (正) 值:
public class Main {
public static void main(String[] args) {
System.out.println(Math.abs(-4.7));
System.out.println(Math.abs(4.7));
System.out.println(Math.abs(3));
}
}
定义与用法
abs()
方法返回数字的绝对 (正) 值。
语法
下列情况之一:
public static double abs(double number)
public static float abs(float number)
public static int abs(int number)
public static long abs(long number)
参数值
参数 | 描述 |
---|---|
number | 必填。指定一个数字 |
技术细节
返回: | 表示指定数字绝对值的 double、float、int 或 long |
---|