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));
}
}
编译以上程序,输出结果为:
8 100.0 90.0
在线实例
字符集 & 工具
最新更新
站点信息
Java Number类