Java abs () method
abs () Returns the absolute value of the parameter. Parameters can be int, float, long, double, short, byte type.
grammar
Various types of methods similar to the following format:
double abs(double d) float abs(float f) int abs(int i) long abs(long lng)
parameter
- Any native data types.
return value
Returns the absolute value of the parameter.
Examples
public class Test{ public static void main(String args[]){ Integer a = -8; double d = -100; float f = -90; System.out.println(Math.abs(a)); System.out.println(Math.abs(d)); System.out.println(Math.abs(f)); } }
Compile the above program, the output is:
8 100.0 90.0