gpt4 book ai didi

java - 在 Java 中扫描整个用户输入以查找匹配的关键字

转载 作者:行者123 更新时间:2023-12-01 11:40:23 25 4
gpt4 key购买 nike

所以我一直在尝试寻找与用户输入的句子相匹配的关键字。我不想输入一个字符串,而是想输入整个句子并检查句子中的关键字。这是我编写的一些代码,但由于某种原因我无法扫描整个句子以查找匹配的关键字。

input = scanner.nextLine().toLowerCase();
for (int i = 0; i < keywords.length; i++) {
if (keywords[i].equalsIgnoreCase(input)) {
System.out.println("Found keyword!");
// TODO: You can optimize this
}
}

关键字列表是

 String[] keywords = { "day", "What book", "professor name", "office",
"hour", "e-mail", "name", "major", "student e-mail",
"group id", "group name", "lecture", "lecture room",
"lecture time", "number of lectures", "current lecture",
"topics of current lecture", "number of test",
"date of a test", "number of assignments", "sure",
"current assignment", "due day" };

最佳答案

 String[] keywords = {"day", "What book", "professor name", "office",
"hour", "e-mail", "name", "major", "student e-mail",
"group id", "group name", "lecture", "lecture room",
"lecture time", "number of lectures", "current lecture",
"topics of current lecture", "number of test",
"date of a test", "number of assignments", "sure",
"current assignment", "due day"};

Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine().toLowerCase();

for (String keyword : keywords) {
if (input.contains(keyword)) {

System.out.println("Found keyword match , " + keyword);

}

尝试上面的代码,它会检查您的输入句子是否包含任何给定的关键字。

关于java - 在 Java 中扫描整个用户输入以查找匹配的关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29573709/

25 4 0
文章推荐: arrays - 数组中的 Fortran 数组
文章推荐: wpf - 在 Expression Blend 2013 中添加 DATATRIGGER 的可视化方式
文章推荐: java -
  • 内的 使用 itext 转换为 PDF 不起作用