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!");
}
}
}
I have made a simple Rock Scissors Paper game, however I want to implement validation so the user will be notified if they enter anything other than Rock Paper Scissors. I had a go with .!equals
however I'm getting an error saying <identifier>
expected.
Thanks!
Wrong syntax:
Player1.!equals
change to:
!Player1.equals
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With