为什么我的循环只运行一次?

时间:2015-08-08 15:16:39

标签: java loops

这是我的代码

executeProgram:
    for (int i= 0; 1< memory.length; i++)
    {   
        String twoDigitMemory = String.format("%02d",memory[i] );
        System.out.print(twoDigitMemory +" ? +");
        accumulator = input.nextInt();

        if (input.nextInt() == -99999)
        {
            System.out.println("*** Program loading completed ***");
            System.out.println("*** Program execution begins  ***");
            break executeProgram;
        }
    }

这是我的输出。我输入123。

***            Welcome to Simpletron!            ***
*** Please enter your program one instruction    ***
*** (or data word) at a time. I will display     ***
*** the location number and a question mark (?)  ***
*** You then type the word for that location.    ***
*** Type -99999 to stop entering your program    ***
00 ? +123

输入123并按Enter键后,我希望for循环再次运行 打印“00?+”但没有任何反应,输入会保存到变量

1 个答案:

答案 0 :(得分:2)

您希望用户输入两次号码。一旦你在accumulater中存储,而另一个只是为了比较不需要的if (input.nextInt() == -99999)这样的数字。相反,您应该使用accumulater变量进行检查,如:

if (accumulater == -99999)
相关问题