该方法给出了参数的绝对值。参数可以是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
转载本站内容时,请务必注明来自W3xue,违者必究。