Java 在字母数组中搜索单词
我有一个名为dictionary的数组列表,其中包括以下字母。 g、 t,c,a,n,d,l,e,t,j,a,q 我希望输出是,例如, 2手柄 3等等。 该数字是从正在搜索的数组开始的偏移量 我希望输出是匹配位置的列表,每个位置都由文本开头的偏移量和找到的字符串组成。Java 在字母数组中搜索单词,java,arrays,Java,Arrays,我有一个名为dictionary的数组列表,其中包括以下字母。 g、 t,c,a,n,d,l,e,t,j,a,q 我希望输出是,例如, 2手柄 3等等。 该数字是从正在搜索的数组开始的偏移量 我希望输出是匹配位置的列表,每个位置都由文本开头的偏移量和找到的字符串组成。 请帮忙 如果我们考虑这类问题,关键是要找出你能找到一个单词的地方的所有不同可能性。以下是我编写的一个方法的框架,该方法将用于此过程: public static String findWords(final char[] char
请帮忙 如果我们考虑这类问题,关键是要找出你能找到一个单词的地方的所有不同可能性。以下是我编写的一个方法的框架,该方法将用于此过程:
public static String findWords(final char[] characters) {
String toRet = "";
// First iterate through every character in the array characters.
for (int i = 0; i < characters.length; i++) {
/*
* Then at each step in this loop, check all possible word
* combinations to see if it's a word. For example, check and see if
* characters[i], characters[i+1] forms a word. Then check and see
* if the word made by adding together characters[i],
* characters[i+1], and characters[i+2] is a word. Then check and
* see if the word formed by adding together the characters
* characters[i], characters[i+1], characters[i+2], characters[i+3]
* is a word.
*/
// Doing the above requires a nested loop inside of the original
// loop.
for (int j = 0; j < characters.length - i; j++) {
// When you do find a word that is formed, then go ahead and add
// to your string toRet the details about the word formed.
}
}
return toRet;
}
这并不能完全回答你的问题,但我希望它能告诉你2发生了什么事?非常感谢你的帮助,现在我知道如何开始了,也知道该怎么做了!!