转自:
下文笔者通过示例的方式讲述使用Math.abs()获取一个参数的绝对值的方法分享,如下所示:
Math.abs()方法功能说明:
返回参数的绝对值
参数类型可以为:int,float,long,double,short,byte
Math.abs语法:
double abs(double d)
float abs(float f)
int abs(int i)
long abs(long lng)
-----返回值说明----
返回参数的绝对值
例:
public class TestClass{ public static void main(String args[]){ Integer a = -99; double d = -22321; float f = -70; System.out.println(Math.abs(a)); System.out.println(Math.abs(d)); System.out.println(Math.abs(f)); } }