462,349 views
0 votes
0 votes
Pls help i need ASAP

Pls help i need ASAP-example-1
User MataMix
by
2.9k points

1 Answer

16 votes
16 votes

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.

User Halaster
by
2.8k points