我是Java编程的新手,我已经研究了所有其他问题,但这些问题似乎都无法帮助我解决我的难题。看,每当我使用我的程序时,所有答案都会出现,而不仅仅是正确的答案。我不知道该如何解决。如果有人有建议,请告诉我。 :)里面没有电脑,只有两个人或你自己。谢谢。我很可能对此进行了过度思考,最终这将变得非常简单。哈哈。

      import java.util.*;

    public class RPS2 {

    public static void main(String[] args) {

        String p1;
        String p2;
        String user1 = "User 1";
        String user2 = "User 2";

        Scanner keyboard = new Scanner(System.in);

        System.out.println("Player 1, please enter your choice [P/R/S]");
        p1 = keyboard.nextLine();
        System.out.println("Player 2, please enter your choice [P/R/S]");
        p2 = keyboard.nextLine();

        if(user1.equalsIgnoreCase("p") && user2.equalsIgnoreCase("r"));
          System.out.println("Paper covers rock, Player 1 wins!");
        if(user1.equalsIgnoreCase("R") && user2.equalsIgnoreCase("S"));
          System.out.println("Paper covers rock, Player 2 wins!");

        if(user1.equalsIgnoreCase("p") && user2.equalsIgnoreCase("s"));
          System.out.println("Scissors cuts paper, Player 2 wins!");
        if(user1.equalsIgnoreCase("S") && user2.equalsIgnoreCase("P"));
          System.out.println("Scissors cuts paper, Player 1 wins!");

        if(user1.equalsIgnoreCase("r") && user2.equalsIgnoreCase("s"));
          System.out.println("Rock breaks scissors, Player 1 wins!");
        if(user1.equalsIgnoreCase("S") && user2.equalsIgnoreCase("R"));
          System.out.println("Rock breaks scissors, Player 2 wins!");

        if(user1.equalsIgnoreCase("user2"));
          System.out.println("Draw");
    }
}

最佳答案

您将答案放在p1p2中,然后比较user1user2。因此,您实际上并没有比较用户输入。

正如@andreicovaciu指出的那样,每个需要删除的;后面都有if

10-07 18:48