Java Math abs() 方法
示例
返回不同数字的绝对值(正值)
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)
参数值
参数 | 描述 |
---|---|
数字 | 必需。指定一个数字 |
技术详情
返回 | 一个表示指定数字绝对值的 double 、float 、int 或 long 值 |
---|
❮ Math 方法