abs(int a):
This method returns the absolute value of an int (integer) value. If the argument is positive, the argument is returned.
If the argument is negative, then the negation of the argument is returned.
Note: If the argument is equal to the value of Integer.MIN_VALUE, the most negative representable
int value, the result is that same value, which is negative.
Parameters:
a: The argument whose absolute value is to be determined
Syntax:
Math.abs(a)
For Example:
num = -10
Math.abs(num) = > It returns 10.
Approach
Java
public class AbsInt {public static void main(String[] args) {int num = -10;System.out.println(Math.abs(num));}}
No comments:
Post a Comment