Java StrictMath.abs(long a)

Syntax

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

public static long abs(long a)

Example

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


public class Main {
/* w  ww.j  av  a2  s .co m*/
  public static void main(String[] args) {
  
    long l1 = 12345678909876L, l2 = -12345678909876L;

    // returns the absolute value of positive long value
    long lAbsValue = StrictMath.abs(l1);
    System.out.println("absolute value of " + l1 + " = " + lAbsValue);    

    // returns the absolute value of negative long value
    lAbsValue = StrictMath.abs(l2);
    System.out.println("absolute value of " + l2 + " = " + lAbsValue);
  }
}

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