java - If 语句错误

标签 java if-statement

好的,我的代码遇到了一些问题。首先是积极的。一切都按我想要的方式进行。首先,我希望我的程序在文本文件中搜索某些关键字或关键字的同义词。这可行,但我的问题在于找不到关键字。我的 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/

相关文章:

linux - Shell 脚本检查字符串是否包含两个输入参数

java - 生产力研究资料

java - 如果一个方法同时被调用太多次会发生什么

java - Spring Data 与 Spring Data JPA 与 JdbcTemplate

c - С 条件下的类型转换

PHP mysql刷新选择数据

java - for-each 循环内的 if-else

java - 泛型 - 正确处理原始类型警告 :

java - Android,setReuseAddress 不起作用

r - 如何使用 ifelse 与 3 个或更多选项比较列?