I need to get the count of numbers less than the first integer in an array using recursion. I am given a function definition as
public static int countGreaterThanFirst(int[]
numbers, int startIndex, int endIndex, int firstNumber){}
I am not supposed to use a loop or global/static variable. How can I convert my implementation below to satisfy the two conditions above. I have recently asked another similar question but this is a bit different due to the need to keep track of the count variable. If someone can help, I will really appreciate. Below is my implementation with a loop.
public static int countGreaterThanFirst(int[] numbers, int startIndex, int endIndex, int firstNumber) {
int greater_than_first = 0;
for (int count = startIndex; count <= endIndex; count++) {
if (numbers[count] > firstNumber) {
greater_than_first++;
}
}
return greater_than_first;
}