Your sortEvens()
method needs to return an int[]
. You've also forgotten to initialize your array.
public static int[] sortEvens (int a[]) {
int evens[] = new int[100];
// ...
}
In getEvens()
method
if ((x == 0)) // ^ (x == 2)) <-- remove this ^ condition
totalEvens += 1;
for (n = 0; n < a.length; n++) { // loop a.length times; not totalEvens
x = (a[n] % 2);
if (x == 0) { // ADDED
evens[y] = a[n];
y++; // increment only when an even is found
} // ADDED
}
In getOdds()
method
for (n = 0; n < a.length; n++) { // loop a.length times; not totalOdds
x = (a[n] % 2);
if (x == 1) { // ADDED
odds[y] = a[n];
y++; // increment only when an odd is found
} // ADDED
}