我试图显示用户猜测的次数,这些是错误:
NumberGame.java:44: 不是语句 System.out.println{"猜测次数:" +guessCount); ^ NumberGame.java:44: ';' 预期 System.out.println{"猜测次数:" +guessCount); ^ NumberGame.java:44: 不是声明 System.out.println{"猜测次数:" +guessCount); ^ NumberGame.java:44: ';' 预期 System.out.println{"猜测次数:" +guessCount); ^ NumberGame.java:48: 解析时到达文件末尾}
我的代码是:
import java.util.Random;
import java.util.Scanner;
public class NumberGame
{
public static void main(String[] args)
{
final int MAX_NUMER = 100;
int number = rand.nextInt(MAX_NUMBER) + 1;
int on_off = 1;
int guessCount = 0;
int guess;
Random rand = new Random();
Scanner keyboard = new Scanner(System.in);
while(on_off == 1)
{
System.out.print("Guess a number between 1 and 100: ");
guess = keyboard.nextInt();
guessCount++;
if(guess < number)
{
System.out.println("Too Low");
guessCount++;
}
if(guess > number)
{
System.out.println("Too High");
guessCount++;
}
if(guess == number)
{
System.out.println("Correct! You win!");
}
}
System.out.println{"Number of guesses: " + guessCount};
}
}
任何帮助将不胜感激!谢谢你的时间!