title: count specific characters in a string (Java)
body: <p>I have a homework assignment to count specific chars in string.</p>
  
  <p>For example: <code>string = "America"</code></p>
  
  <p>The output should be = <code>a appear 2 times, m appear 1 time, e appear 1 time, r appear 1 time, i appear 1 time and c appear 1 time</code></p>
  
  <pre><code>public class switchbobo {
  
  /**
   * @param args
   */     // TODO Auto-generated method stub
    public static void main(String[] args){
      String s = "BUNANA";
      String lower = s.toLowerCase();
      char[] c = lower.toCharArray(); // converting to a char array
      int freq =0, freq2 = 0,freq3 = 0,freq4=0,freq5 = 0;
  
      for(int i = 0; i&lt; c.length;i++) {
          if(c[i]=='a') // looking for 'a' only
            freq++;
          if(c[i]=='b')
            freq2++;
          if (c[i]=='c') {
            freq3++;
          }
  
          if (c[i]=='d') {
            freq4++;
          }       
      }
      System.out.println("Total chars "+c.length);
      if (freq &gt; 0) {
        System.out.println("Number of 'a' are "+freq);
      }
    }
  }
  </code></pre>
  
  <p>code above is what I have done, but I think it is not make sense to have 26 variables (one for each letter). Do you guys have alternative result?</p>