/** * @author lautturi.com * Java example: get the absolute value of a number */ import java.util.*; public class Lautturi { public static void main(String[] args) { int i = 12; double d = 1.414d; float f = 3.14f; Integer I = 123; System.out.println(Math.abs(i)); System.out.println(Math.abs(d)); System.out.println(Math.abs(f)); System.out.println(Math.abs(I)); int i2 = -12; double d2 = -1.414d; float f2 = -3.14f; Integer I2 = -123; System.out.println(Math.abs(i2)); System.out.println(Math.abs(d2)); System.out.println(Math.abs(f2)); System.out.println(Math.abs(I2)); } }
output:
12 1.414 3.14 123 12 1.414 3.14 123