There is a much better way of doing it, by taking the count variable out. This should also do it:
public static int displayOccu(int[] a, int n, int i)
{
if(i == a.length)
return 0;
else if(a[i] == n)
return 1+displayOcc(a,n,i+1);
else
return displayOcc(a,n,i+1);
}
This code is very similar to examples of summation with recursion. If the number is a hit, we add one and check the rest, otherwise we just check the rest. When it reaches the end of the array, it returns 0 to the previous call, and then adds together each 1 as the recursive call returns to where it was called.
I haven't compiled or tested the code, but in theory it should work.