【发布时间】:2011-02-17 19:10:05
【问题描述】:
这个怎么写?我需要帮助,特别是我的 nextWord 方法
package code;
import java.util.HashMap;
public class WordCounter {
/**
* Reads a file (identified by inputFilePath), one character at a time, and tracks
* word counts using a java.util.HashMap<String,Integer>.
*
* A word is defined as a contiguous sequence of characters that does not contain
* word separator characters, where word separator characters are: ' ', '\t', '\n',
* ',' and '.'
*
* You may use only CharacterFromFileReader to read characters from the input file.
*
* In order to keep your code readable, break your code into several methods. Only
* the wordCounts method may be public; define meaningful private helper methods that
* you call from the wordCounts method.
* @returns a HashMap containing the word->count mappings
*/
public HashMap<String,Integer> wordCounts(String inputPath) {
return new HashMap<String, Integer>();
}
private String nextWord(CharacterFromFileReader iterator) {
while(iterator.hasNext()){
//make loop that takes each word an saves it to a string until u hit a space break
String s = "";
if(iterator.hasNext()){
}
}
return null;
}
}
【问题讨论】:
-
您是否尝试过自己解决问题?你试过什么?就目前而言,您是在要求我们为您做功课。
-
是的,我有..到目前为止我已经完成的代码是我所做的,关于制作循环和保存每个单词的评论是我的想法..但是我知道该怎么做