I am stuck on this one problem on Arrays. I haven’t started the program yet because I really don’t understand what it wants me to do! Here is the problem:
Write a method called wordLengths that accepts a String representing a file name as its argument. Your method should open 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. For example, the following text:
Before sorting:
12 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:
1: 0
2: 6 [There should be 6 * printed here]
3: 10 [There should be 10 * printed here]
4: 0
5: 5 [There should be 5 * printed here]
6: 1 [There should be 1 * printed here]
7: 2 [There should be 2 * printed here]
8: 2 [There should be 2 * printed here]
So StackOverflow is rather limited, so I wasn’t able to show you the full style of the output, but in summary, the “Before Sorting:” part that is followed by 2 sentences are one group, “After sorting:” and the 2 sentences below are another group. The “before” and “after” sorting are separated by one space.
I don’t get how the output is achieved, that’s my problem. I have a feeling that the 1-8 represents line numbers, but what do the 0, 6, 10, etc. represent? Because when I counted the word lengths, they exceeded 6 or 10…
It’d be a great help if someone could explain to me what this program wants me to do.
Thanks in advance!
1 – 8 are length of a word (or a number, or a token); -18 has length 3, and “sorting:” is 8.
0, 6, 10… are the number of occurrences for words that have the length 1, 2, 3…
BTW, this is not really a question fitting here but hope this could help.