I was given a phrase and I am suppose to count all the letters total.
I'm thinking of making the phrase an array but then I forgot how to make it read each index/word and count the letters in it.
Could I use .length for the array indexes or tokens with .next?
Please help. I just need an example and I'll take it from there.
This was the question btw:
Write a method named wordStats that accepts as its parameter a Scanner holding a sequence of words and that reports the total number of words and the average word length. You may assume that the Scanner isn't empty. For example, suppose the Scanner is scanning an input source that contains the following words:
To be or not to be, that is the question.
For the purposes of this problem, we will use whitespace to separate words. That means that some words include punctuation, as in "be,". (This is the same definition that the Scanner uses for tokens.) For the input above, your method should produce exactly the following output:
Total words = 10
Average length = 3.2
This post has been edited by JaJEff: 18 August 2010 - 11:48 PM