Java Math.abs(int a)

Syntax

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

public static int abs(int a)

Example

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


// ww w .j  a va 2  s.  c o  m
public class Main {

   public static void main(String[] args) {
      int x = 123;
      int y = -123;

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

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