【发布时间】:2019-06-15 08:49:13
【问题描述】:
对于 Java 中的单词搜索游戏,我要求用户输入任意数量的单词(如果他们想停止添加更多单词,他们将键入一个 'q'),并且此输入存储在数组列表,然后将其转换为名为@987654322@ 的一维数组,然后我在 main 中调用一个方法来开始游戏。这是代码sn-p:
System.out.println("Grid of the game");
for(char[] j : letterGrid) {
System.out.println(j);
}
System.out.println("Search for these words...\n");
for(String j : words) {
System.out.print(j + ", ");
}
System.out.print("Enter the Word: ");
String word = br.readLine();
System.out.print("Enter Row Number: ");
int row = Integer.parseInt(br.readLine());
//matching the word using regex
Pattern pattern = Pattern.compile(word, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(letterGrid[row-1]);
letterGrid 是一个二维字符数组,但在它显示的行:Matcher matcher = pattern.matcher(letterGrid[row-1]); 发生错误,它说:The method matcher(CharSequence) in the type Pattern is not applicable for the arguments. 我尝试更改我的程序并将 letterGrid 转换为一维字符串数组,它工作正常为此,但不适用于二维字符数组。我用随机字母和用户词(水平、垂直或对角线。没有向后)填充 letterGrid。
我被困在这个问题上,我目前正在寻找解决问题的方法,但我想我也可以在这里提问,因为这里的人们提供了很好的建议和建议。任何帮助将不胜感激!
【问题讨论】:
-
请提供minimal reproducible example。阅读代码转储既费力又烦人。
-
好的。我将删除一些代码,让我的问题和描述不那么冗长。
-
我已经编辑了我的问题。
标签: java string multidimensional-array char wordsearch