Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Maths/AbsoluteMax.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
*/
public class AbsoluteMax {
public static void main(String[] args) {
int[] numbers = new int[]{3, -10, -2};
int[] testnums = {-2, 0, 16};
assert absMax(testnums) == 16;

int[] numbers = {3, -10, -2};
System.out.println("absMax(" + Arrays.toString(numbers) + ") = " + absMax(numbers));
}

Expand Down
5 changes: 4 additions & 1 deletion Maths/AbsoluteMin.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
*/
public class AbsoluteMin {
public static void main(String[] args) {
int[] numbers = new int[]{3, -10, -2};
int[] testnums = {4, 0, 16};
assert absMin(testnums) == 0;

int[] numbers = {3, -10, -2};
System.out.println("absMin(" + Arrays.toString(numbers) + ") = " + absMin(numbers));
}

Expand Down
8 changes: 4 additions & 4 deletions Maths/AbsoluteValue.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package Maths;

/**
* @author PatOnTheBack
*/

public class AbsoluteValue {

public static void main(String[] args) {
assert absVal(-13) == 13;
assert absVal(0) == 0;
assert absVal(100) == 100;

int value = -34;
System.out.println("The absolute value of " + value + " is " + absVal(value));
}
Expand Down
5 changes: 5 additions & 0 deletions Maths/MaxValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public static int max(int a, int b) {
}

public static void main(String[] args) {
assert max(-3,3) == 3;
assert max(-6,-20) == -6;
assert max(100,32) == 100;
assert max(13,13) == 13;

int a = 3;
int b = 4;
System.out.format("max:%d between %d and %d", max(a, b), a, b);
Expand Down
5 changes: 5 additions & 0 deletions Maths/MinValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public static int min(int a, int b) {
}

public static void main(String[] args) {
assert min(-3,3) == -3;
assert min(-6,-20) == -20;
assert min(100,32) == 32;
assert min(13,13) == 13;

int a = 3;
int b = 4;
System.out.format("min:%d between %d and %d", min(a, b), a, b);
Expand Down
32 changes: 32 additions & 0 deletions Maths/PythagoreanTriple.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package Maths;

/**
* https://en.wikipedia.org/wiki/Pythagorean_triple
*
*/
public class PythagoreanTriple {
public static void main(String[] args) {
assert isPythagTriple(3,4,5);
assert isPythagTriple(5,12,13);
assert isPythagTriple(6,8,10);
assert !isPythagTriple(10,20,30);
assert !isPythagTriple(6,8,100);
assert !isPythagTriple(-1,-1,1);
}

/**
* Check if a,b,c are a Pythagorean Triple
*
* @param a x/y component length of a right triangle
* @param b y/x component length of a right triangle
* @param c hypotenuse length of a right triangle
* @return boolean <tt>true</tt> if a, b, c satisfy the Pythagorean theorem, otherwise <tt>false</tt>
*/
public static boolean isPythagTriple(int a, int b, int c) {
if(a <= 0 || b <= 0 || c <= 0) {
return false;
} else {
return (a * a) + (b * b) == (c * c);
}
}
}