Easy Tutorial
❮ Java Object Hashcode Data Stack ❯

Java abs() Method

Java Number Class


The abs() method returns the absolute value of the argument. The argument can be of type int, float, long, double, short, or byte.

Syntax

The method formats for each type are similar to the following:

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

Parameters

Return Value

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 = -90f;        

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

Compiling the above program will output the following:

8
100.0
90.0

Java Number Class

❮ Java Object Hashcode Data Stack ❯