title: For loop that counts how many characters repeat in a string, then removes the repeated characters
body: <p>Example: attack at noon = a3t3c1k1 2n2o2</p>
  
  <p>It also counts spaces.
  Here is what I have, but it doesn't seem to be returning correctly:</p>
  
  <pre><code>String getCount(String str) {
      String R = "";
      int l = S.length();
      int cnt = 1;
  
      for (int i = 0; i &lt; l; i++)
          for (int j = i + 1; j &lt; l; j++)
              if (S.charAt(j) == S.charAt(i)) {
                  cnt++;
                  R = R + S.charAt(i)+""+cnt;
                  System.out.print(S.charAt(i) + cnt);
              }      
      return R;
  }
  </code></pre>