gpt4 book ai didi

java - 如何正确记分

转载 作者:行者123 更新时间:2023-12-01 07:47:42 24 4
gpt4 key购买 nike

该程序的设计目的是在每次识别关键字时给出一个分数,但并没有这样做。我确信修复非常简单,但我却忽略了。

我还需要在未检测到关键字时显示此内容。最终,我希望能够根据重要性将值硬编码到每个关键字。而不是每个单词只有一个点。

import java.util.*;

public class KeyWords {

public static void main(String[] args) {
String who = null, what = null, where = null, when = null,
why = null, how = null;

String[] keywords = {"who", "what", "where", "when", "why", "how"};

int RunningTotal = 0;
Scanner scanner = new Scanner(System.in);
System.out.println("Please enter a sentence\n");
String input = scanner.nextLine().toLowerCase();

for (String keyword : keywords) {
if (input.contains(keyword)) {
System.out.println("Found keyword: " + keyword);
}

switch (keyword) {
case "who":
RunningTotal++;
break;
case "what":
RunningTotal++;
break;
case "where":
RunningTotal++;
break;
case "when":
RunningTotal++;
break;
case "why":
RunningTotal++;
break;
case "how":
RunningTotal++;//Broken, always adds all 6
break;
default:
System.out.println("No keywords detected...");//Does not work
}
}//for loop

System.out.println(RunningTotal);
if (RunningTotal <= 3) {
System.out.println("Lack of communication skills");
}
}

}//class

最佳答案

如果您转到 switch 语句,您将看到您正在评估从关键字列表中提取的关键字。

我建议你去掉 switch 语句。这是没有用的。您可以使用循环内部的 if 语句来执行相同的操作。我不会提供代码,但我认为这是一个巨大的提示。

关于java - 如何正确记分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48305552/

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