Answer:
static int[] randomArray(int nrElements) {
Random rd = new Random(); // creating Random object
int[] arr = new int[nrElements];
for (int i = 0; i < arr.length; i++) {
arr[i] = rd.nextInt(1000);
}
return arr;
}
static int numberOfEvens(int[] arr) {
int count = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] % 2 == 0) {
count++;
}
}
return count;
}
Step-by-step explanation:
The random numbers are between 0 and 1000 for simplicity.
A number is even if the remainder after division by 2 is 0. This is the % operation.