Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Java abs() Method

Java abs() Method

Java Number ClassThe Java Number class


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

Syntax

The method format for each type is 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

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

)

)

;

   

   

}

}

Compile the above program; the output is:



8

100.0

90.0


Java Number ClassThe Java Number class