March 19th, 2013, 06:25 PM
Counting spaces or # of words
Hi guys, I need help on calculating the average word length.
// Counts number of the words
numWords = 0; // Resets numWords Value
stringScan = new Scanner(sentence);
word = stringScan.next();
System.out.println("The number of words in this sentence is: " + numWords);
// Calculates average word length
wordLength = cleanString.length();
System.out.println("Word Length: " + wordLength);
avgWordLength = wordLength / totalWords;
System.out.println("The average word length is: " + avgWordLength);
March 20th, 2013, 10:01 AM
Can you explain what your problem is? What does the program currently print out?
Can you post its output and explain what is wrong with it?
Are you having problems with integer arithmetic? 4/10 = 0 and 4.0/10 = 0.4