Merge pull request #809 from PatOnTheBack/master
Added Maths Folder & Absolute Value Program
This commit is contained in:
commit
d6fda6f0f6
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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user