Java Math.abs(float a)

Syntax

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

public static float abs(float a)

Example

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


//from www  .j a  v a  2  s.co m

public class Main {

   public static void main(String[] args) {

      float x = 1.2345f;
      float y = -123.45f;

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

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