gpt4 book ai didi

java - 这怎么能写呢?我需要有关下一个 Word 方法的帮助

转载 作者:行者123 更新时间:2023-12-01 05:49:44 26 4
gpt4 key购买 nike

这个怎么写?我特别需要有关 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;
}
}

最佳答案

这个怎么样?

String words[] = str.split("[ ,\\t\\n,\\.]");

要生成 str,您可以对 iterator 循环中的 StringBuilder 使用 append 操作。

关于java - 这怎么能写呢?我需要有关下一个 Word 方法的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5033414/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com