mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-07 09:45:04 +08:00
Merge pull request #809 from PatOnTheBack/master
Added Maths Folder & Absolute Value Program
This commit is contained in:
24
Maths/AbsoluteValue.java
Normal file
24
Maths/AbsoluteValue.java
Normal file
@ -0,0 +1,24 @@
|
||||
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 " + absVal(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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user