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,18 +1,33 @@
package Maths;
import java.util.Arrays;
import java.util.Random;
public class FindMax {
//Driver
/**
* Driver Code
*/
public static void main(String[] args) {
int[] array = {2, 4, 9, 7, 19, 94, 5};
assert findMax(array) == 94;
Random random = new Random();
/* random size */
int size = random.nextInt(100) + 1;
int[] array = new int[size];
/* init array with random numbers */
for (int i = 0; i < size; i++) {
array[i] = random.nextInt() % 100;
}
assert Arrays.stream(array).max().getAsInt() == findMax(array);
}
/**
* find max of array
*
* @param array the array contains element
* @return max value
* @return max value of given array
*/
public static int findMax(int[] array) {
int max = array[0];