Java abs() Method
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
- Any primitive data type.
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
The Java Number class