2019-08-08 09:58:58 +08:00
|
|
|
package Maths;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author PatOnTheBack
|
|
|
|
*/
|
|
|
|
|
2019-08-15 09:12:33 +08:00
|
|
|
public class AbsoluteValue {
|
2019-08-08 09:58:58 +08:00
|
|
|
|
|
|
|
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-08 09:58:58 +08:00
|
|
|
}
|
|
|
|
|
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-08 09:58:58 +08:00
|
|
|
}
|
|
|
|
|
2019-08-15 09:12:33 +08:00
|
|
|
}
|