Java Number abs() 方法
描述
该方法返回参数的绝对值。参数可以是int、float、long、double、short、byte类型。
语法
以下是该方法的所有变体的语法 −
double abs(double d)float abs(float f)int abs(int i)long abs(long lng)
参数
下面是参数的详细信息 −
任何原始数据类型。返回值
该方法返回参数的绝对值。示例
public class Test { public static void main(String args[]) { Integer a = -8; double d = -100; float f = -90; System.out.println(Math.abs(a)); System.out.println(Math.abs(d)); System.out.println(Math.abs(f)); }}这将产生以下结果 –
输出
8100.090.0
