1
這是我的代碼爲什麼我的循環只運行一次?
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?+」,但沒有任何反應,輸入也得到保存到變量
你實際上意味着寫'1
你的if應該是'if(accumulator == -99999)'? – SMA
你有一個錯字。我懷疑你的for循環應該是:'for(int i = 0; i
scrappedcola