问题描述
/ * 此应用程序使用数字玩Hi-Lo猜谜游戏。该程序会选择一个介于1到100(含)之间的随机数,然后反复提示用户猜测该数字。
每次猜测时,都会通知用户他们是正确的还是猜测是不正确的(无论是高还是低)。
程序将继续接受猜测,直到用户正确猜测或选择退出为止。它还将计数并报告用户的猜测数目,以正确猜测所选的数目。如果猜测值超出范围(1到100),则将建议用户更正其猜测值,并且该猜测值不会计算在内。在每个游戏结束时(通过退出或正确的猜测),将要求用户再次玩。如果他们选择继续玩其他游戏,程序将循环播放直到用户选择停止为止。 * /
System.out.println("Let's play a guessing game!");
System.out.println("Pick a number between " + MIN + " and " + MAX +
" (inclusive). ");
guess = scan.nextInt();
while
{
if (guess < MIN || guess > MAX)
{
System.out.println("Your guess is out of range!");
System.out.println("Pick a number between " + MIN + " and " + MAX +
" (inclusive). ");
}
count++;
else if(guess == answer)
{
System.out.println("CONGRATULATIONS! The number was " + answer +
". You guessed correctly in " + count + " tries!");
System.out.println("Would you like to play again?");
System.out.print("Type \"Y\" to play and \"N\" to quit. ");
String play = scan.nextLine();
if(play.equalsIgnoreCase("Y"))
{
System.out.println("Game on!");
}
else if(play.equalsIgnoreCase("N"))
{
System.out.println("Thanks for playing! Good-bye.");
return;
}
}
else if (guess < answer)
{
System.out.println("Sorry,your guess " + guess + " is too low. "
+ "Try again!");
}
else if (guess > answer)
{
System.out.println("Sorry,your guess " + guess + " is too high. "
+ "Try again!");
}
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)