Hi,
I have to write a recursive method to count the number of user entered even integers in an array (the array size is up to 100). Here's what I have....
public static int countEven (int numbers[], int startIndex, int endIndex)
{
if(startIndex==endIndex)
if (numbers[startIndex]%2 == 0)
return 1;
else
return 0;
else
if (numbers[startIndex]%2 == 0)
return 1 + countEven (numbers, startIndex+1, endIndex);
else
return countEven (numbers, startIndex+1, endIndex);
}
This compiles and runs, but all it ever returns is 100 (I understand this is the size of the array). I've been tooling around with it for a while now, but I can't seem to get the result I want. Obviously, it's counting every index in the array whether it has 100 values or not, but I can't figure out how to fix it. Thank you in advance or any help.