SORRY我知道這個遊戲還有其他的帖子,但我的問題是具體的。我剛剛開始學習Java並將這款HiLo遊戲扔在一起,但我正在努力掙到2件東西 -Java HiLo遊戲 - 無法產生新的猜測
1)如果用戶想再玩一次,我如何獲得它來生成一個新選擇? 2)如果用戶選擇中止遊戲,我沒有得到消息產生
幫助我可愛請,我是新的,容易受到Java!
package lab4;
import java.util.Scanner;
import java.util.Random;
public class hilo
{
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//randomly pick a number between 1-100
Random rand = new Random();
int pick = rand.nextInt(100) + 1;
int count = 0;
boolean play = true;
//prompt user to guess
Scanner scan = new Scanner(System.in);
System.out.println("*---------------------------------*");
System.out.println("* Guess a number between 1-100: *");
System.out.println("* (enter \"0\" to end at any time) *");
System.out.println("*---------------------------------*");
int guess = scan.nextInt();
//on each guess, say if too low or too high
while (play = true)
{
while (guess != pick && guess !=0)
{
if (guess < pick)
{
count++;
System.out.println("Higher...");
System.out.println(pick);
guess = scan.nextInt();
}
else if (guess > pick)
{
count++;
System.out.println("Lower...");
System.out.println(pick);
guess = scan.nextInt();
}
}
if (guess == pick)
{
System.out.println("You got it! It only took you " + count + " guesses.");
System.out.println("Want to play again?");
System.out.println("* Guess a number between 1-100: *");
System.out.println("* (enter \"0\" to end at any time) *");
guess = scan.nextInt();
if (guess != 0)
play = true;
else
play = false;
}
}
if (play = false || guess == 0)
{
System.out.println("Bummer. See you next time!");
}
}
}