-2

我想我在某处遗漏了括号,但我已经搜索了 3 个小时,找不到问题所在,谷歌搜索也没有帮助我。

我尝试在 if then 语句中添加结束大括号/方括号,但随后出现了一堆错误。一旦有人发现我做了什么,可能会是一个“duh”的时刻。在此先感谢。

错误:NumberGame.java:45:错误:解析时到达文件末尾} ^ NumberGame.java:51:错误:解析时到达文件末尾 2 个错误

import java.util.*;

public class NumberGame
{
    public static void main(String[] args)
    {
        double R = 0;
        double tryit = 0;
        double a = 0;
        double b = 0;
        while (tryit == 0)
        {
            R = 0;
            while (R != 1)
            {
                a = (int)(Math.Random() * 10);
                b = (int)(Math.Random() * 10);
                if (a -b >= 0){
                    R = 1;
            }
        }
        double inpt = -7;
            while (inpt != (a-b))
            {
                Sytem.out.println("What is " + a + " minus " + b + " ? ");

                inpt = scanner.inpt = new Scanner(System.in);

                if ((a -b) == inpt){
                    System.out.print("Good job, you are correct");
                    System.out.println("Play again?, Yes or No?:");
                    String inpt2 = scanner.inpt2 = new Scanner(System.in);
                if ((a-b) != inpt){
                    System.out.println("Sorry try again");

            }
        if (inpt2 == "No"){
            System.out.println("Thanks for playing");
            break;
        if (inpt2 == "no"){
            System.out.println("Thanks for playing");
            break;
    }
}
4

3 回答 3

2

每个if语句都有一个左大括号,但没有一个右大括号。

于 2015-05-10T23:58:57.823 回答
1

您的if陈述需要右括号。

    if (a -b >= 0){
        R = 1;
    } // Closing bracket

    ....

    if ((a -b) == inpt) {
        System.out.print("Good job, you are correct");
        System.out.println("Play again?, Yes or No?:");
        String inpt2 = scanner.inpt2 = new Scanner(System.in);
    } // Closing bracket
    if ((a-b) != inpt){
        System.out.println("Sorry try again");
    } // Closing bracket

    ...

    // I think you only need one of these and not two
    if (inpt2 == "No"){
        System.out.println("Thanks for playing");
        break;
    } // Closing bracket
    if (inpt2 == "no"){
        System.out.println("Thanks for playing");
        break;
    } // Closing bracket
于 2015-05-10T23:58:32.980 回答
0

您的if陈述需要一个右括号:

if (a -b >= 0){
    R = 1;
}
于 2015-05-10T23:58:18.860 回答