title: Recursively counting character occurrences in a string
body: <p>Im making a program to count the number of times a character is found in a string. This is what my method looks like:</p>
  
  <pre><code>public static int count (String line, char c)
  {
      int charOccurences = 0; //= 0;
  
      for (int x = 0 ; x &lt; line.length () ; x++)
      {
          if (line.charAt (x) == c)
          {
              charOccurences++;
              line = line.substring (0, x) + line.substring (x + 1);
              return count (line, c);
          }
          else
              return charOccurences;
      }
      return charOccurences;
  }
  </code></pre>
  
  <p>It always returns 0, due to the fact that once the method calls itself it sets <code>charOccurences</code> back to 0. But i need to declare that variable for the method to work. I cant figure any way around this. Any help would be appreciated.</p>