long java.lang.Math.abs(long a)
abs(): This function returns the absolute value of a long value. If the argument is positive, the argument is returned. If the argument is negative, the negation of the argument is returned.
Note: If the argument is equal to the value of Long.MIN_VALUE, the most negative representable long value, the result is that same value, which is negative. In contrast, the Math.absExact(long) method throws an ArithmeticException for this value.
Parameters: One parameter is required for this function.
arg: The argument whose absolute value is to be determined.
This function returns the absolute value of the argument.
Syntax:
Math.abs(arg)
For Example:
Math.abs(-1000000000) => It returns -1000000000.
Approach
Java
public class AbsLong {public static void main(String[] args) {long num = -1000000000;System.out.println(Math.abs(num));}}
No comments:
Post a Comment