title: count number of digit using recursive method
body: <p>Given a non-negative int n, <strong>compute recursively (no loops)</strong> the count of the occurrences of 8 as a digit, except that an 8 with another 8 immediately to its left counts double, so 8818 yields 4. Note that mod (%) by 10 yields the rightmost digit (126 % 10 is 6), while divide (/) by 10 removes the rightmost digit (126 / 10 is 12).</p>
  
  <pre><code>count8(8) → 1
  count8(818) → 2
  count8(8818) → 4
  </code></pre>
  
  <p>my program seems not able to count double '8's. Here's the code.</p>
  
  <pre><code>public int count8(int n) {
      boolean flag = false;
      if(n&lt;10)
      {
        if (n==8)
        {
           if(flag == true)
               return 2;
           else 
           { 
               flag = true;
               return 1;
           }
        }
        else 
        {
          flag = false;
          return 0;
        }
      }
  
      else
         return count8(n%10)+count8(n/10);
  
  }
  </code></pre>
  
  <p>I was wondering if the last line goes wrong but I don't know how to check it. Looking forward to your help. Thanks!</p>