好的,我的代码遇到了一些问题。首先是积极的。一切都按我想要的方式进行。首先,我希望我的程序在文本文件中搜索某些关键字或关键字的同义词。这可行,但我的问题在于找不到关键字。我的 if(found) 语句似乎从未达到。我尝试使用调试器,但我还没有看到问题是什么。
public static void main(String args[]) throws ParseException, IOException {
/* Initialization */
List<DicEntry> synonymMap = populateSynonymMap(); // populate the map
Scanner scanner = new Scanner(System.in);
String input = null;
/* End Initialization */
System.out.println("Welcome ");
System.out.println("What would you like to know?");
System.out.print("> ");
input = scanner.nextLine().toLowerCase();
String[] inputs = input.split(" ");
for (String ing : inputs) {
boolean found = false;
for (DicEntry entry : synonymMap) { // iterate over each word of the
// sentence.
if (entry.pattern.matcher(input).matches()) {
found = true;
// System.out.println(entry.key);
parseFile(entry.key);
System.out
.println(" Would you like to update this information ? ");
String yellow = scanner.nextLine();
if (yellow.equals("yes")) {
removedata(entry.key);
break;
}
if (yellow.equals("no")) {
System.out.println("Have a good day");
break;
}
}
if (found) {
Writer();
// break;
}
}
// break;
}
}
}
假设 Writer()、removedata()、parsefile() 方法有效,有人可以帮忙吗?
最佳答案
如果您回答"is"或“否”以外的任何问题,则会到达 if(found){}。 或者您可以将 if(found){} 循环放在 for 语句之外。
关于java - If 语句错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29995251/