不是声明

 李磊g114826 发布于 2023-02-11 19:56

我正在从书中学习用java编写代码.它给出了一个猜谜游戏的例子并给出了代码.我想把它作为参考.但我不断收到错误.它可能是我键入它的方式因为我正在读它的点燃它有点搞砸了.

有很多这样的错误,但没有像我这样的错误.我正在尝试制作一个猜谜游戏,但我一直收到这个错误:

GuessingGame.java:17:不是语句(int)(Math.random()*10)+ 1;

码:

import java.util.Scanner;
public class GuessingGame
{
    static Scanner sc = new
Scanner(System.in);
    public static void
main(String[] args)
    {
    bolean keepPlaying = true;
    System.out.println("Let's play a guessing game!");
    while (keepplaying)
    {
        bolean validInput;
        int number, guess;
        String answer;
        // Pick a random number = 
    (int)(Math.random() * 10) + 1;
        // Get the guess
        System.out.print("What do you think it is? ");
        do
        {
            guess = sc.nextInt();
            validInput = true;
            if ((guess < 1) || (guess > 10))
            {
                System.out.print
                    ("I said between 1 and 10. "
                    + "Try again: ");
                validInput = false;
            }
        }while (!validInput);
        // Check the guess
        if (guess == number)
            System.out.println(
        "You're right!");
        else
            System.out.println(
        "You're wrong! " + "The number was " + number);
        // Play again?
        do
        {
            System.out.println("\nPlay again? (Yes or No)");
            answer = sc.next();
            validInput = true;
            if (asnwer.equalsIgnoreCase("Yes"));
            else if (answer.egualsIgnoreCase("No")-
                keepPlaying = false);
            else
                        validInput = false;
        } while (!validInput);
    }
    System.out.println("\nThank you for playing!");
}

}

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有