mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-11 14:12:36 +08:00
Update AbsoluteValue.java
This commit is contained in:
@ -4,24 +4,21 @@ package Maths;
|
|||||||
* @author PatOnTheBack
|
* @author PatOnTheBack
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class AbsoluteValue {
|
public class AbsoluteValue {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
int value = -34;
|
int value = -34;
|
||||||
|
System.out.println("The absolute value of " + value + " is " + absVal(value));
|
||||||
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 is less than zero, make value positive.
|
||||||
if (value < 0) {
|
*
|
||||||
return -value;
|
* @param value a number
|
||||||
}
|
* @return the absolute value of a number
|
||||||
|
*/
|
||||||
return value;
|
public static int absVal(int value) {
|
||||||
|
return value > 0 ? value : -value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user