title: Count letters in a string Java
body: <p>I'm doing an assignment where I'll have to code a program to read in a string from user and print out the letters in the string with number of occurrences. <em>E.g. "Hello world" in which it should print out "h=1 e=1 l=3 o=2 ... etc.", but mine only write "hello world" and the amount of letters in total.</em> I can't use the hashmap function, only arrays. Can someone give me a hint or two on how to proceed from the written code below to get my preferred function? I don't understand exactly how to save the written input in array.</p>
  
  <p>Here's my code so far.</p>
  
  <pre><code>public class CountLetters {
      public static void main( String[] args ) {
          String input = JOptionPane.showInputDialog("Write a sentence." );
          int amount = 0;
          String output = "Amount of letters:\n";
  
          for ( int i = 0; i &lt; input.length(); i++ ) {
              char letter = input.charAt(i);
              amount++;
              output = input;
          }
          output += "\n" + amount;
          JOptionPane.showMessageDialog( null, output,
                               "Letters", JOptionPane.PLAIN_MESSAGE ); 
      }
  }
  </code></pre>