logo Practice-It logo

BJP3 Exercise 7.18: wordLengths

Language/Type: Java arrays file processing Scanner tallying
Author: Whitaker Brand (on 2013/04/01)

Write a method called wordLengths that accepts a Scanner representing an input file as its argument. Your method should read from the given file, count the number of letters in each token in the file, and output a result diagram of how many words contain each number of letters. Use tabs before the asterisks so that they'll line up. If there are no words of a given length, omit that line from the output.

For example, if the file contains the following text:

Before sorting:
13 23 480 -18 75
hello how are you feeling today

After sorting:
-18 13 23 75 480
are feeling hello how today you

your method should produce the following output to the console:

2: 6    ******
3: 10   **********
5: 5    *****
6: 1    *
7: 2    **
8: 2    **

You may assume that no token in the file is more than 80 characters in length.

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.