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

问题描述:

这是我的代码为什么我的循环只运行一次?

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之后,按进入我希望在for循环再次运行 印刷“00?+”,但没有任何反应,输入也得到保存到变量

+2

你实际上意味着写'1

+2

你的if应该是'if(accumulator == -99999)'? – SMA

+1

你有一个错字。我怀疑你的for循环应该是:'for(int i = 0; i scrappedcola

你是期待用户输入两次号码。一旦你存储在累加器中,而另一个只是比较不需要的数字,如if (input.nextInt() == -99999)。相反,你应该使用accumulater变量检查,如:

if (accumulater == -99999)