Given a non-negative int n, how do i return the count of the occurrences of a digit e.g 7, so for example 717 yields 2? (no loops). Here is my code but it doesn't work well.
public int count7(int n) {
int count = 0;
if(n==7){
count++;
return count;
}
else if(n>7 && n<100)
return count7(n/10)+count7(n%10);
else if( n>100)
return count7(n/10)+count7(n%10);
else return 0;
}