I created this program to run infinite times asking the user to enter a choice(rock or paper or scissor), which seems to work fine. The problem is no else ....if or if ....else statements are satisfied. Whatever input i give it just prints out the else statement in the else statement, (Enter a valid choice). I cant find the mistake i made so ill link my code below..... Thanks in advance.
import java.util.Scanner;
import java.util.Random;
public class apples {
public static void main(String args[]){
Scanner input = new Scanner(System.in);
Random number = new Random();
String rps[] = {"rock", "paper", "scissor"};
String player;
String ai;
int rand, pscore=0, aiscore=0;
while(1 < 2){
System.out.println("Take your pick \nrock \npaper \nscissor");
player = input.nextLine();
rand = number.nextInt(3);
ai = rps[rand];
System.out.println(ai);
if(player == ai){
pscore+=0;
aiscore+=0;
System.out.println("Your opponent chose " + ai + "\tYour score= "+ pscore + "\tOpponents score = "+aiscore);
System.out.print("\n");
continue;
}else{
if(player == "rock" && ai == "paper"){
aiscore+=1;
pscore+=0;
System.out.println("Your opponent chose " + ai + "\tYour score= "+ pscore + "\tOpponents score = "+aiscore);
System.out.print("\n");
continue;
}else if(player == "rock" && ai == "scissor"){
pscore+=1;
aiscore+=0;
System.out.println("Your opponent chose " + ai + "\tYour score= "+ pscore + "\tOpponents score = "+aiscore);
System.out.print("\n");
continue;
}else if(player == "paper" && ai == "rock"){
pscore+=1;
aiscore+=0;
System.out.println("Your opponent chose " + ai + "\tYour score= "+ pscore + "\tOpponents score = "+aiscore);
System.out.print("\n");
continue;
}else if(player == "paper" && ai == "scissor"){
aiscore+=1;
pscore+=0;
System.out.println("Your opponent chose " + ai + "\tYour score= "+ pscore + "\tOpponents score = "+aiscore);
System.out.print("\n");
continue;
}else if(player == "scissor" && ai == "rock"){
aiscore+=1;
pscore+=0;
System.out.println("Your opponent chose " + ai + "\tYour score= "+ pscore + "\tOpponents score = "+aiscore);
System.out.print("\n");
continue;
}else if(player == "scissor" && ai == "paper"){
aiscore+=0;
pscore+=1;
System.out.println("Your opponent chose " + ai + "\tYour score= "+ pscore + "\tOpponents score = "+aiscore);
System.out.print("\n");
continue;
}else{
System.out.println("Enter a valid choice");
System.out.print("\n");
continue;
}
}
}
}
}