Groovy - abs()


Advertisements

The method gives the absolute value of the argument. The argument can be int, float, long, double, short, byte.

Syntax

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

Parameters − Any primitive data type.

Return Value − This method Returns the absolute value of the argument.

Example

Following is an example of the usage of this method.

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

When we run the above program, we will get the following result −

8 
100.0 
90.0
groovy_numbers.htm
Advertisements