Java循环不工作

Java循环不工作,java,while-loop,Java,While Loop,所以我正在写一个小程序,但是我的while循环似乎不起作用,我在互联网上到处寻找教程,我知道我需要增加J,但我似乎不知道在哪里,因为当我修复一件事情时,另一部分停止工作! 有人能告诉我怎么做才能解决这个问题吗 int j=0;//which group we're checking while(response==0){ { if(inArray(quote.toLowerCase(),greetin

所以我正在写一个小程序,但是我的while循环似乎不起作用,我在互联网上到处寻找教程,我知道我需要增加J,但我似乎不知道在哪里,因为当我修复一件事情时,另一部分停止工作! 有人能告诉我怎么做才能解决这个问题吗

int j=0;//which group we're checking
            while(response==0){
                {
                    if(inArray(quote.toLowerCase(),greetings[j*2]))
                    {
                        response=2;
                        int r=(int)Math.floor(Math.random()*greetings[(j*2)+1].length);
                        addText("\n-->Miku:\t"+greetings[(j*2)+1][r]);
                        try (BufferedReader br = new BufferedReader(new FileReader("mikuname.txt"))) {
                            String name;
                            while ((name = br.readLine()) != null) {
                            addText(name +"!");
                            }
                        } catch (IOException e1) {
                            // Do something with the IO problem that occurred while reading the file
                        }
                    }
                }
                if(response==0)
                {
                    if(inArray(quote.toLowerCase(),chatBot[j*2]))
                    {
                        response=2;
                        int r=(int)Math.floor(Math.random()*chatBot[(j*2)+1].length);
                        addText("\n-->Miku:\t"+chatBot[(j*2)+1][r]);
                    }
                }
                if(response==0)
                {
                    response=1;
                }
            }

您可能想要做的是在每次迭代中增加j。我还没有看过您的逻辑,也没有试图理解您想要完成什么,但是添加
j++
将使它在循环的每个迭代中增加1。否则
j*2
将始终为0

int j=0;//which group we're checking
        while(response==0){
            {
                j++;
                if(inArray(quote.toLowerCase(),greetings[j*2]))
                {
                    response=2;
                    int r=(int)Math.floor(Math.random()*greetings[(j*2)+1].length);
                    addText("\n-->Miku:\t"+greetings[(j*2)+1][r]);
                    try (BufferedReader br = new BufferedReader(new FileReader("mikuname.txt"))) {
                        String name;
                        while ((name = br.readLine()) != null) {
                        addText(name +"!");
                        }
                    } catch (IOException e1) {
                        // Do something with the IO problem that occurred while reading the file
                    }
                }
            }
            if(response==0)
            {
                if(inArray(quote.toLowerCase(),chatBot[j*2]))
                {
                    response=2;
                    int r=(int)Math.floor(Math.random()*chatBot[(j*2)+1].length);
                    addText("\n-->Miku:\t"+chatBot[(j*2)+1][r]);
                }
            }
        }

为什么在
while
之后有两个
{
?你打算用这个while循环完成什么?我修复代码中错误的方法是使用我的调试器。我建议你在调试器中逐步检查代码,看看它为什么这样做。我正在创建一个聊天机器人!(别担心,这只是因为我觉得制作它很有趣,这样它就不会在互联网上到处乱发了)在我的代码顶部,我得到了两个字符串,称为问候语和聊天机器人,现在,在这两个字符串中都有{“我能说什么”}{“机器人会回答什么”},问候语部分工作得很好,因为其中只有一行,但是,在聊天机器人中,有更多的行用于不同的问题。问题是,在我的循环中,它似乎只检查我说的话是否在聊天机器人的第一行,我想让它检查整个内容++j缺失,但如果你添加它,你还必须添加一些bounds支票。例如问候语[j*2]你应该解释你的答案,让OP知道他的错误。我知道我必须使j增量为1,但我似乎不能让它通过循环多次,比如,我可以使j增量为1,但它只会看到chatbot中的第二行,然后它就停止了,有没有办法在循环的第二部分的某处添加j++呢?(它在chatBot中的位置)您的while循环是while
response==0
,在代码的最后,如果在第一次传递结束时仍然是0,您总是将response设置为1。这将阻止循环再次运行。我编辑此答案以反映该代码。
我没有查看您的逻辑或试图理解您试图实现的目标
-那么,也许不建议使用。。。