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.


/*ww  w  .  j a va2s .c  o m*/

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.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable