test using rand numbers

This commit is contained in:
shellhub
2020-08-23 12:40:30 +08:00
parent d6947d0fbd
commit c771089882
9 changed files with 130 additions and 67 deletions

View File

@@ -1,7 +1,24 @@
package Maths;
import java.util.Random;
public class MaxValue {
/**
* Driver Code
*/
public static void main(String[] args) {
Random rand = new Random();
/* test 100 times using rand numbers */
for (int i = 1; i <= 100; ++i) {
/* generate number from -50 to 49 */
int a = rand.nextInt(100) - 50;
int b = rand.nextInt(100) - 50;
assert max(a, b) == Math.max(a, b);
}
}
/**
* Returns the greater of two {@code int} values. That is, the
* result is the argument closer to the value of
@@ -15,15 +32,4 @@ public class MaxValue {
public static int max(int a, int b) {
return a >= b ? a : 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);
}
}