In my program I need a for-each loop which counts the number of evens in the given array and increments the variable even for each one. When I use a standard
even
The i is the number itself, not the index. so you should:
i
for (int i : numbers) { if (i % 2 == 0) { // <-- use i not numbers[i] even++; } else { odd++; } }