JavaAlgorithms/Maths/AbsoluteValue.java
2019-08-15 09:12:33 +08:00

25 lines
491 B
Java

package Maths;
/**
* @author PatOnTheBack
*/
public class AbsoluteValue {
public static void main(String[] args) {
int value = -34;
System.out.println("The absolute value of " + value + " is " + absVal(value));
}
/**
* If value is less than zero, make value positive.
*
* @param value a number
* @return the absolute value of a number
*/
public static int absVal(int value) {
return value > 0 ? value : -value;
}
}