Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在字母数组中搜索单词_Java_Arrays - Fatal编程技术网

Java 在字母数组中搜索单词

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

我有一个名为dictionary的数组列表,其中包括以下字母。 g、 t,c,a,n,d,l,e,t,j,a,q

我希望输出是,例如, 2手柄 3等等。 该数字是从正在搜索的数组开始的偏移量

我希望输出是匹配位置的列表,每个位置都由文本开头的偏移量和找到的字符串组成。
请帮忙

如果我们考虑这类问题,关键是要找出你能找到一个单词的地方的所有不同可能性。以下是我编写的一个方法的框架,该方法将用于此过程:

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发生了什么事?非常感谢你的帮助,现在我知道如何开始了,也知道该怎么做了!!