该方法给出参数的绝对值。参数可以是int,float,long,double,short,byte。
abs() - 语法
以下是此方法的所有变体-
double abs(double d) float abs(float f) int abs(int i) long abs(long lng)
abs() - 返回值
- 此方法返回参数的绝对值。
abs() - 示例
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