.abs()
christian.dinh2476 total contributions
Published Jun 18, 2021Updated Aug 24, 2022
Contribute to Docs
The Math.abs()
method returns the absolute value of the argument.
Syntax
Math.abs(n)
Absolute values are the non-negative versions of the value without considering the positive/negative sign.
Example
The following example uses Math.abs()
to return the absolute values of -6.5
, 2
, and -340.8
:
class AbsoluteValue {public static void main(String[] args) {double x = -6.5;int y = 2;double z = -340.8;System.out.println(Math.abs(x));System.out.println(Math.abs(y));System.out.println(Math.abs(z));}}
This produces the following output:
6.52340.8
All contributors
- christian.dinh2476 total contributions
- Anonymous contributorAnonymous contributor3071 total contributions
- StevenSwiniarski474 total contributions
- Victoria-DR22 total contributions
- christian.dinh
- Anonymous contributor
- StevenSwiniarski
- Victoria-DR
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.