게임을 다시 시작하는 방법을 알 수 없습니다. System.out.println ("Ok, 다시 게임 해 봅시다.")이라고 적혀있는 부분을 넣어야한다고 생각합니다. 다시 시작하려면 무엇이 필요합니까? 내가 뭘 놓치고 있니?번호를 추측 한 후에이 숫자 추측 게임을 다시 시작하려면 어떻게합니까?
import java.util.Random;
import java.util.Scanner;
public class GuessMyNumber {
public static void main(String[] args) {
Random Bob = new Random();
int NumToGuess = Bob.nextInt(20);
int NumOfTries = 0;
Scanner Bill = new Scanner(System.in);
int guess;
boolean win = false;
while (win == false) {
System.out.println("I'm thinking of a number between 1 and 20, can you guess it?");
guess = Bill.nextInt();
NumOfTries++;
if (guess == NumToGuess) {
win = true;
}
else if (guess < NumToGuess) {
System.out.println("Your guess is too low");
}
else if (guess > NumToGuess) {
System.out.println("Your guess is too high");
}
}
System.out.println("Congratulations!");
System.out.println("The number was " + NumToGuess);
System.out.println("It took you " + NumOfTries + " tries");
while (win == true) {
String YesOrNo;
YesOrNo = Bill.nextLine();
System.out.println("Would you like to play again? " + YesOrNo);
YesOrNo = Bill.nextLine();
if (YesOrNo.equalsIgnoreCase("yes"))
{
System.out.println("Ok, let's play again.");
}
else
{
System.out.println("Ok, maybe next time.");
}
}
}
}
당신은 당신이 영원히 루프에 머물 것이 아니라 프로그램 흐름의 시작 부분으로 돌아갈 것을 놓치고있어. – EpicPandaForce
@ crpittman18 그런데'''Bob.nextInt (20)''는 0 (포함)과 20 (제외) 사이의 숫자를 생성합니다. – mezzodrinker