目录

abs()

该方法给出了参数的绝对值。 参数可以是int,float,long,double,short,byte。

语法 (Syntax)

double abs(double d) 
float abs(float f) 
int abs(int i) 
long abs(long lng)

Parameters - 任何原始数据类型。

Return Value - 此方法返回参数的绝对值。

例子 (Example)

以下是此方法的使用示例。

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
↑回到顶部↑
WIKI教程 @2018