Java Tutorial

Java Control Statements

Object Oriented Programming

Java Built-in Classes

Java File Handling

Java Error & Exceptions

Java Multithreading

Java Synchronization

Java Networking

Java Collections

Java List Interface

Java Queue Interface

Java Map Interface

Java Set Interface

Java Data Structures

Java Collections Algorithms

Java Miscellaneous

Advanced Java

Java APIs & Frameworks

Java Useful Resources

Java - abs() Method



Description

The method gives the absolute value of the argument. The argument can be int, float, long, double, short, byte.

Syntax

Following are all the variants of this method −

double abs(double d)
float abs(float f)
int abs(int i)
long abs(long lng)

Parameters

Here is the detail of parameters −

  • Any primitive data type.

Return Value

  • This method Returns the absolute value of the argument.

Example

public class Test { 

   public static void main(String args[]) {
      Integer a = -8;
      double d = -100;
      float f = -90;

      System.out.println(Math.abs(a));
      System.out.println(Math.abs(d));     
      System.out.println(Math.abs(f));    
   }
}

This will produce the following result −

Output

8
100.0
90.0
java_numbers.htm
Advertisements