這怎麼寫?我需要幫助,特別是使用我的nextWord方法這個怎麼寫?我特別需要使用我的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;
}
}
您曾經試圖弄清楚你自己?你有什麼嘗試?就目前而言,你要求我們爲你做功課。 – Blorgbeard 2011-02-17 19:14:01