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








Syntax

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

public static long abs(long a)

Example

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

/*  w ww  .jav a2  s. com*/

public class Main {

   public static void main(String[] args) {
      long x = 12345678901234L;
      long y = -12345678901234L;

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

The code above generates the following result.