Update AbsoluteValue.java
This commit is contained in:
parent
9751ac5e98
commit
b882515eb0
@ -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;
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user