我在Arrays上遇到了这个问题。我还没有开始这个项目,因为我真的不明白它想要我做什么!这是问题所在:
编写一个名为wordLengths的方法,该方法接受表示文件名的String作为其参数。您的方法应该打开给定的文件,计算文件中每个标记的字母数,并输出包含每个字母数的单词数的结果图。例如,以下文字:
排序前:
12 23 480 -18 75
你好,今天感觉如何排序后:
-18 13 23 75 480
今天感觉你好吗
您的方法应该向控制台生成以下输出:
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]
所以StackOverflow相当有限,所以我无法向您展示输出的完整风格,但总的来说,“排序之前:”部分后跟2个句子是一组,“排序后: “下面的两句话是另一组。 “之前”和“之后”排序由一个空格分隔。
我不知道如何实现输出,这是我的问题。我有一种感觉,1-8代表行号,但0,6,10等代表什么?因为当我计算单词长度时,它们超过6或10 ...... 如果有人能向我解释这个程序要我做什么,那将是一个很大的帮助。
提前致谢!
答案 0 :(得分:2)
1 - 8是单词的长度(或数字或标记); -18的长度为3,“排序:”为8。
0,6,10 ...是长度为1,2,3的单词的出现次数...
顺便说一句,这不是一个适合这里的问题,但希望这可能有所帮助。答案 1 :(得分:1)
根据这个....
编写一个名为wordLengths的方法,该方法接受表示文件名的String作为其参数。您的方法应该打开给定的文件,计算文件中每个标记的字母数,并输出包含每个字母数的单词数的结果图。例如,以下文字:
我们将其分解为几个步骤......
A Write a method called word Lengths
B that accepts a String representing a file name as its argument.
C Your method should open the given file,
D count the number of letters in each token in the file,
E and output a result diagram of how many words contain each number of letters.
F 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
落入以下意识形态......
1是0因为 没有单词包含1个字母
2是6因为 六个字包含两个字母(12 23 75 13 23 75)
3是10因为 十个字包含三个字母(480 -18你怎么样-18 480是你的方式)
4是0因为 没有单词包含四个字母
5是5因为 五个字包含五个字母(今天你好,今天问好)
6是1因为 一个单词包含六个字母(之前)
7是2因为 两个单词包含七个字母(感觉)
8是2因为 两个单词包含八个字母(排序:排序:)