Given an array of n integers, count the number of times a value appears determined. Solve the problem with a recursive algorithm
-
int contar (int [] array, int valor, int posInici)
-
array
: array with values. -
valor
: value search. -
posInici
: Initial position where we started to search.
I pass the code that I have done:
package tema2;
public class Problema3 {
public static void main(String[] args) {
int [] array={3,12,314,1234,3};
int valor=3;
int posInici=1;
Problema3 programa = new Problema3();
programa.comptar(array,valor,posInici);
System.out.println(posInici);
}
public static int comptar(int [] array,int valor,int posInici) {
int j=0;
if(posInici == array.length) {
j++;
}
if(valor == array[posInici]) {
return array valor posInici + 1;
}
}
}