Update AbsoluteValue.java

This commit is contained in:
Yang Libin
2019-08-15 09:12:33 +08:00
committed by GitHub
parent 9751ac5e98
commit b882515eb0

View File

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