title: Counting letters in a string using two for-loops
body: <p>I have to read the string <code>"hello world"</code> and output each letter's frequency using only for loops. The instructor hinted that I'd need to use two loops and gave us the following code to begin:</p>
  
  <pre><code>int ch, count;
  for (ch ='a'; ch &lt;='z'; ch++) {
    //count the number of occurrences in a line
    //Print the count&gt;0
  }
  </code></pre>
  
  <p><strong>Edit:</strong> I figured I'd necro this question and post the solution I found a year ago due to the fact that this question has been getting a decent amount of hits.</p>
  
  <pre><code>int count;
  int value;
  for (int i=65; i&lt;91; i++) {
      count=0;
      for (int j=0; j&lt;S.length; j++) {
          value=(int)S[j];
          if (value == i) {
               count++;
          }
      }
      if (count&gt;0) 
         System.out.println((char)i+" -- "+count);
  }
  </code></pre>