目录

abs()

描述 (Description)

该方法给出了参数的绝对值。 参数可以是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)

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));    
   }
}

这将产生以下结果 -

输出 (Output)

8
100.0
90.0
↑回到顶部↑
WIKI教程 @2018