diff --git a/Maths/AbsoluteValue.java b/Maths/AbsoluteValue.java index dfe3915ad..82faf81ff 100644 --- a/Maths/AbsoluteValue.java +++ b/Maths/AbsoluteValue.java @@ -4,24 +4,21 @@ package Maths; * @author PatOnTheBack */ - public class AbsoluteValue { +public class AbsoluteValue { public static void main(String[] args) { - int value = -34; - - System.out.println("The absolute value of " + value + " is " + abs_val(value)); - + System.out.println("The absolute value of " + value + " is " + absVal(value)); } - public static int abs_val(int value) { - // If value is less than zero, make value positive. - if (value < 0) { - return -value; - } - - return 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; } - } +}