Java Math abs() 方法
定义和用法
abs()
方法返回数字的绝对(正)值。
实例
返回不同数字的绝对(正)值:
System.out.println(Math.abs(-4.7)); System.out.println(Math.abs(4.7)); System.out.println(Math.abs(3));
语法
以下之一:
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 值,表示指定数字的绝对值。 |
---|