Home >>Java Math Methods >Java Math.abs() method
Java Math.abs() method is used to returns the absolute (Positive) value of a value int. This approach gives the statement its absolute value. The statement could be int, double, long, or float.
public static int abs(int i) public static double abs(double d) public static float abs(float f) public static long abs(long lng)
The argument whose absolute value is to be determined
This method is used to returns the absolute value of the argument
public class MyClass
{
public static void main(String args[])
{
int x = 12;
int y = -42;
System.out.println(Math.abs(x));
System.out.println(Math.abs(y));
System.out.println(Math.abs(Integer.MIN_VALUE));
}
}
public class MyClass
{
public static void main(String args[])
{
double x = -12.76;
double y = -23.67;
System.out.println(Math.abs(x));
System.out.println(Math.abs(y));
System.out.println(Math.abs(5.0 / 0));
}
}