-2

我用 Java 编写了一个程序,它允许用户使用扫描仪根据运动员人数命名某些运动,反之亦然。我几乎使用了我能想到的所有组合来运行它,并且效果很好。在作为类项目提交以进行评分后,我们应该使用的自动在线编译器返回 2 个错误。教授告诉我,我的拼写/标点符号应该有问题,但我无法确定。有人可以看看并告诉我他们是否找到了什么吗?感谢所有帮助!

import java.util.Scanner;

public class SportsQuiz {

public static void main(String[] args) {

    Scanner s = new Scanner(System.in);

    final String PROMPT = "Enter 1 to guess a sport, 2 to guess how"
            + " many players: ";

    final int NUMOFBASKET = 5;
    final int NUMOFBASE = 9;
    final int NUMOFCURL = 4;
    final int NUMOFFOOT = 11;

    System.out.print(PROMPT);

    int promptnum = s.nextInt();

    if(promptnum == 1) {

        System.out.print("Choose number of players: ");

        int numplayers = s.nextInt();

        s.nextLine();

        if(numplayers != NUMOFBASKET && numplayers != NUMOFBASE 
                && numplayers != NUMOFCURL && numplayers != NUMOFFOOT){

            System.out.print("Invalid choice.");

        } else {

            System.out.print("Which sport has " + numplayers
                    + " players? ");

            String playsport = s.nextLine();

            if(playsport.equals("Basketball")
                    ||playsport.equals("basketball")
                    && numplayers == NUMOFBASKET) {

                System.out.print("Correct!");

            } else if(playsport.equals("Football")
                    ||playsport.equals("football") 
                    && numplayers == NUMOFFOOT) {

                System.out.print("Correct!");

            } else if(playsport.equals("Baseball")
                    ||playsport.equals("baseball")
                    && numplayers == NUMOFBASE) {

                System.out.print("Correct!");       

            } else if(playsport.equals("Curling")
                    ||playsport.equals("curling")
                    && numplayers == NUMOFCURL) {

                System.out.print("Correct!");

            } else {

                System.out.print("Incorrect");

            }

        }

    } else if(promptnum == 2) {

        System.out.print("Choose a sport: ");

        s.nextLine();

        String sport = s.nextLine();

        if(sport.equals("Basketball")||sport.equals("basketball")) {

            System.out.print("How many players are on a " + sport 
                    + " team? ");

            int numsportplayers = s.nextInt();

            if(numsportplayers == NUMOFBASKET){

                System.out.print("Correct!");

            } else {

                System.out.print("Incorrect!");

            }



        } else if(sport.equals("Baseball")||sport.equals("baseball")) {

            System.out.print("How many players are on a " + sport 
                    + " team? ");

            int numsportplayers = s.nextInt();

            if(numsportplayers == NUMOFBASE){

                System.out.print("Correct!");

            } else {

                System.out.print("Incorrect!");

            }

        } else if(sport.equals("Football")||sport.equals("football")) {

            System.out.print("How many players are on a " + sport 
                    + " team? ");

            int numsportplayers = s.nextInt();

            if(numsportplayers == NUMOFFOOT){

                System.out.print("Correct!");

            } else {

                System.out.print("Incorrect!");

            }

        } else if (sport.equals("Curling")||sport.equals("curling")) {

            System.out.print("How many players are on a " + sport 
                    + " team? ");

            int numsportplayers = s.nextInt();

            if(numsportplayers == NUMOFCURL){

                System.out.print("Correct!");

            } else {

                System.out.print("Incorrect!");
            }

        } else {

            System.out.print("Invalid Choice.");

        }

    } else {

        System.out.print("Invalid Choice.");

    }

  }

}

提前致谢!

4

1 回答 1

0

在一种情况下,您的“不正确”没有感叹号。

此外,在一种情况下,您有“无效的选择”。但在另一个你有“无效的选择”。(大写 C)。

我猜这是两个错误。

于 2013-02-18T03:50:22.047 回答