From 9751ac5e98a10012819d437371b27eed91b54218 Mon Sep 17 00:00:00 2001 From: PatOnTheBack <51241310+PatOnTheBack@users.noreply.github.com> Date: Wed, 7 Aug 2019 21:58:58 -0400 Subject: [PATCH 1/2] Added Maths Folder & Absolute Value Program --- Maths/AbsoluteValue.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Maths/AbsoluteValue.java diff --git a/Maths/AbsoluteValue.java b/Maths/AbsoluteValue.java new file mode 100644 index 00000000..dfe3915a --- /dev/null +++ b/Maths/AbsoluteValue.java @@ -0,0 +1,27 @@ +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 " + abs_val(value)); + + } + + public static int abs_val(int value) { + // If value is less than zero, make value positive. + if (value < 0) { + return -value; + } + + return value; + + } + + } From b882515eb005c0856dd5d665e2fc3cd164b9f37b Mon Sep 17 00:00:00 2001 From: Yang Libin Date: Thu, 15 Aug 2019 09:12:33 +0800 Subject: [PATCH 2/2] Update AbsoluteValue.java --- Maths/AbsoluteValue.java | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/Maths/AbsoluteValue.java b/Maths/AbsoluteValue.java index dfe3915a..82faf81f 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; } - } +}