title: Count the Frequency of X letter words?
body: <p>i have to create a program where it counts the frequency/occurrence of X letter of words, i have got the program to work out the frequency of the words and the lengths but now i need to work out the mean length of the words entered, i am really stuck on this so if anyone can help i will be grateful</p>
  
  <p>This is the code i have as of yet:</p>
  
  <pre><code>import javax.swing.JOptionPane;
  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>