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>
。
ありがとう!