Java Data Type Tutorial - Java Math.abs(double a)








Syntax

Math.abs(double a) has the following syntax.

public static double abs(double a)

Example

In the following code shows how to use Math.abs(double a) method.

public class Main {
/*w w w . j  a v  a  2 s. co m*/
   public static void main(String[] args) {
      double x = 2.1d;
      double y = -0.12345d;

      System.out.println(Math.abs(x));
      System.out.println(Math.abs(y));
      System.out.println(Math.abs(-9.5));
   }
}

The code above generates the following result.