以下代码未显示任何错误,但是,当我尝试输入user play
时,我遇到了大量错误。
public static void rockPaperScissors(Scanner input) {
// TODO Auto-generated method stub
String user = null, computer = null;
int computerRand;
Random num = new Random();
System.out.println("Lets play Rock, Paper, Scissors.\nPlease enter a move\n");
computerRand=num.nextInt(3)+1;
if (computerRand==1)
computer="R";
else if (computerRand==2)
computer="P";
else if (computerRand==3)
computer="S";
System.out.println("Enter user play");
user=input.nextLine();
if (user==computer){
System.out.println("Tie. Try over!");
}
else if (user==("R")){
if (computer==("S"))
System.out.println("Rock beats Scissors. You win!");
else if (computer==("P"))
System.out.println("Paper covers rock. CPU wins..");
}
else if (user==("P")){
if (computer==("S"))
System.out.println("Scissors cut paper. CPU wins..");
else if (computer==("R"))
System.out.println("Paper covers rock. You win!");
}
else if (user==("S")){
if (computer==("P"))
System.out.println("Scissors cuts paper. You win!");
else if (computer==("R"))
System.out.println("Rock beats scissors. CPU wins..");
}
System.out.println("Computer play is: "+computer);
}
答案 0 :(得分:1)