java - Need help fixing this Rock Paper Scissors game -


this question has answer here:

the following code not show errors, however, when tried input user play, tons of errors.

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 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. 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. win!");     }     else if (user==("s")){         if (computer==("p"))             system.out.println("scissors cuts paper. win!");     else if (computer==("r"))             system.out.println("rock beats scissors. cpu wins..");     }              system.out.println("computer play is: "+computer);  } 

  "else if (user==("r")){" 

here comparing strings '==' not think trying

(user.equals("r"))  

would help.

checkout this question


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -