Added Maths Folder & Absolute Value Program
This commit is contained in:
parent
15f2ebdd1d
commit
9751ac5e98
27
Maths/AbsoluteValue.java
Normal file
27
Maths/AbsoluteValue.java
Normal file
@ -0,0 +1,27 @@
|
||||
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 " + abs_val(value));
|
||||
|
||||
}
|
||||
|
||||
public static int abs_val(int value) {
|
||||
// If value is less than zero, make value positive.
|
||||
if (value < 0) {
|
||||
return -value;
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user