dimanche 19 septembre 2021

hello in my java program i had made small "rock" "paper" "scissor" game but it skips all Statement and directly print else statement [duplicate]

**hello in my java program I had made small "rock" "paper" "scissor" game but it skips all Statement and directly print else statement **

String [] a = {"r","p","s"};

while(true){
System.out.println("enter you move");
String userinput =sc.nextLine();
String comp = a[ran.nextInt(a.length)];
 if (userinput == comp) {
     System.out.println("oops its a tie");
 }
 else if (userinput == "r" && comp == "s" || userinput == "p" && comp == "r"
         || userinput == "s" && comp == "p") {
     System.out.println("You Win!");
     
 } else {
     System.out.println("Computer Win! :"+comp);
 }
     
 System.out.println("playagin(y/n)");   
    String playagain = sc.nextLine();
    if (!playagain.equals("y")) {
    break;
        }
} 

Aucun commentaire:

Enregistrer un commentaire