JavaAlgorithms/Maths/AbsoluteValue.java

25 lines
491 B
Java
Raw Normal View History

package Maths;
/**
* @author PatOnTheBack
*/
2019-08-15 09:12:33 +08:00
public class AbsoluteValue {
public static void main(String[] args) {
int value = -34;
2019-08-15 09:12:33 +08:00
System.out.println("The absolute value of " + value + " is " + absVal(value));
}
2019-08-15 09:12:33 +08:00
/**
* 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;
}
2019-08-15 09:12:33 +08:00
}