We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9751ac5 commit b882515Copy full SHA for b882515
Maths/AbsoluteValue.java
@@ -4,24 +4,21 @@
4
* @author PatOnTheBack
5
*/
6
7
- public class AbsoluteValue {
+public class AbsoluteValue {
8
9
public static void main(String[] args) {
10
-
11
int value = -34;
12
13
- System.out.println("The absolute value of " + value + " is " + abs_val(value));
14
+ System.out.println("The absolute value of " + value + " is " + absVal(value));
15
}
16
17
- public static int abs_val(int value) {
18
- // If value is less than zero, make value positive.
19
- if (value < 0) {
20
- return -value;
21
- }
22
23
- return value;
24
+ /**
+ * 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;
25
26
27
+}
0 commit comments