我正在执行的Java测验未检测到正确答案

时间:2019-12-29 20:14:13

标签: java

我正在为一个五个问题的测验编写Java程序。我只写了一个问题,因为每当我检查玩家是否回答正确答案时,它就永远不会接受正确答案。

我看不到此程序有任何问题,它与该问题无关。

public class Quiz
{
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);

        int playerScore = 0;
        String playerAnswer;
        double percentage;
        int count = 0;
        for(count = 0; count < 5; count++){
            if(count == 4){
                System.out.println("Who can save you 15% or more on car insurance?");
                System.out.println();
                System.out.println("A. Geico");
                System.out.println("B. Carmeleon");
                System.out.println("C. Karen");
                System.out.println("D. Flo");
                System.out.println();

                System.out.print("Enter the answer: ");
                playerAnswer = input.next();
                System.out.println();

                playerAnswer = playerAnswer.toUpperCase();
                System.out.println(playerAnswer);

                if(playerAnswer == "A"){
                    playerScore += 1;
                    System.out.println("Correct!");
                }
                else{
                    System.out.println("Nah, you're wrong.");
                }
            }
        }
    }
}```

0 个答案:

没有答案