71
Java Math.abs() method
The java.lang.Math.abs() method returns the absolute (Positive) value of a int value. This method gives the absolute value of the argument. The argument can be int, double, long and float.
Syntax:
Parameters:
Return:
- If we provide positive or negative value as argument, this method will result positive value.
- If the argument is Infinity, this method will result Positive Infinity.
- If the argument is NaN, this method will return NaN.
- If the argument is equal to the value of Integer.MIN_VALUE or Long.MIN_VALUE, the most negative representable int value or long value, the result is that same value, which is negative.
Example 1:
Output:
78 48 -2147483648
Example 2:
Output:
47.63 894.37 Infinity
Example 3:
Output:
73.02 428.0
Example 4:
Output:
78730343 4839233 -9223372036854775808
Next TopicJava Math