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
This is the code i have as of yet:
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:
";
for ( int i = 0; i < input.length(); i++ ) {
char letter = input.charAt(i);
amount++;
output = input;
}
output += "
" + amount;
JOptionPane.showMessageDialog( null, output,
"Letters", JOptionPane.PLAIN_MESSAGE );
}
}
See Question&Answers more detail:os