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 {
/*from   ww  w  . ja  v  a2s .c o 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.





















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