gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 03:18:40 25 4
gpt4 key购买 nike

这是我的代码

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?+”但没有任何反应,输入确实保存到变量中

最佳答案

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

if (accumulater == -99999)

关于java - 为什么我的循环只运行一次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31895438/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com