I have a problem that gives Stack Overflow Error on my code. I'm trying to find a number in one array, but I have to do it in a recursive function, and gives that error.
public static int linear(int[] array, int num, int indice) {
if (indice < array.length-1) {
if (array[indice] == num) {
return indice;
} else {
ocurrencias++;
linear(array, num, indice + 1);
}
}
return -1;
}
If you can help me I would appreciate. My english is a little rusty, sorry.