Groovy - abs()
该方法给出参数的绝对值。 参数可以是 int、float、long、double、short、byte。
语法
double abs(double d) float abs(float f) int abs(int i) long abs(long lng)
参数 − 任何原始数据类型。
返回值 − 该方法返回参数的绝对值。
示例
以下是该方法的使用示例。
class Example {
static void main(String[] args) {
Integer a = -8;
double b = -100;
float c = -90;
System.out.println(Math.abs(a));
System.out.println(Math.abs(b));
System.out.println(Math.abs(c));
}
}
当我们运行上面的程序时,会得到下面的结果 −
8 100.0 90.0

