title: Java - Number of occurrences of a digit in a number without loop
body: <p>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.</p>
  
  <pre><code> public int count7(int n) {
  int count = 0;
    if(n==7){
    count++;
  
    return count;
    }
   else if(n&gt;7 &amp;&amp; n&lt;100)
  
    return count7(n/10)+count7(n%10);
  
    else if( n&gt;100)
  
    return count7(n/10)+count7(n%10);
  
    else return 0;
  
  }
  </code></pre>