logo Practice-It logo

wordStats

Language/Type: Java file processing Scanner
Author: Whitaker Brand

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 (as an integer) and the average word length (as an un-rounded real number). 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
Type your solution here:


This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.