import java.util.Scanner;
public class RockPaperScissors
{
public static void main (String[] args)
{
Scanner scan = new Scanner (System.in);
System.out.println("Player 1: Choose rock, paper or scissors: ");
String Player1 = scan.next().toLowerCase();
System.out.println("Player 2: Choose rock, paper or scissors: ");
String Player2 = scan.next().toLowerCase();
System.out.println ("Player 1 chose " + Player1);
System.out.println ("Player 2 chose " + Player2);
if (Player1.!equals("rock" + "paper" + "scissors")
{
System.out.println ("Please insert either Rock Paper or Scissors!);
}
if (Player1.equals(Player2))
{
System.out.println ("Its a tie!");
}
if ((Player1.equals("rock")) && (Player2.equals("paper")))
{
System.out.println ("Player 2 wins!");
}
else if ((Player1.equals("paper")) && (Player2.equals("rock")))
{
System.out.println ("Player 1 wins!");
}
if ((Player1.equals("scissors")) && (Player2.equals("paper")))
{
System.out.println ("Player 1 wins!");
}
else if ((Player1.equals("paper")) && (Player2.equals("scissors")))
{
System.out.println ("Player 2 wins!");
}
if ((Player1.equals("rock")) && (Player2.equals("scissors")))
{
System.out.println ("Player 1 wins!");
}
else if ((Player1.equals("scissors")) && (Player2.equals("rock")))
{
System.out.println ("Player 2 wins!");
}
}
}
我制作了一个简单的剪刀石头布游戏,但是我想实现验证,以便用户在输入除石头剪刀布以外的任何内容时会收到通知。我试过了,.!equals
但是我收到一个错误,说是<identifier>
预期的。
谢谢!