Java 之abs() 方法的功能说明
Java abs() 方法的功能说明
abs()方法返回参数的绝对值。
参数的类型可以是:int,float,long,double,short,byte。
abs()方法的语法
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 = -9;
double b = -120;
float c = -88;
System.out.println(Math.abs(a));
System.out.println(Math.abs(b));
System.out.println(Math.abs(c));
}
}
/*
以上代码运行后,将输出以下信息
9
120.0
88.0
*/
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


