int num = -5; int absValue = Math.abs(num); System.out.println("Absolute value of " + num + " is " + absValue);
Absolute value of -5 is 5
double num = -10.5; double absValue = Math.abs(num); System.out.println("Absolute value of " + num + " is " + absValue);
Absolute value of -10.5 is 10.5In both examples, we used the Math.abs method to find the absolute value of a given expression. The package library used is java.awt.