gpt4 book ai didi

java - while 循环在每次迭代后不更新 i

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

    while (var<10)  
{

String line=keyboard.nextLine();
input = line.charAt(0);

game.makeGuess(input);
game.getDisguisedWord();
game.isFound();
System.out.println(game.getDisguisedWord());
System.out.println(game);
System.out.println(game.getWrong());
int i=0;
i++;
if (var<i+game.getDisguisedWord().length()-1)
System.out.print("Guess #" + game.guessCount()+": ");
var=game.getWrong();
if (game.isFound())
var=10;
}

不确定出了什么问题,但如果我打印出 i,它只会停留在 1。我需要这样做才能停止打印:(

最佳答案

int i=0 是错误。它在每次迭代中将 i 初始化为 0,因此在下一步的 i++ 之后,您的 i 值保持为 1。要仅初始化一次,请将其放在 while 循环之外。

关于java - while 循环在每次迭代后不更新 i,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17290390/

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