Skip to content

Commit b882515

Browse files
authored
Update AbsoluteValue.java
1 parent 9751ac5 commit b882515

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

Maths/AbsoluteValue.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,21 @@
44
* @author PatOnTheBack
55
*/
66

7-
public class AbsoluteValue {
7+
public class AbsoluteValue {
88

99
public static void main(String[] args) {
10-
1110
int value = -34;
12-
13-
System.out.println("The absolute value of " + value + " is " + abs_val(value));
14-
11+
System.out.println("The absolute value of " + value + " is " + absVal(value));
1512
}
1613

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-
14+
/**
15+
* If value is less than zero, make value positive.
16+
*
17+
* @param value a number
18+
* @return the absolute value of a number
19+
*/
20+
public static int absVal(int value) {
21+
return value > 0 ? value : -value;
2522
}
2623

27-
}
24+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy