我很困惑,爲什麼我不能進入這兩個if語句之一。我錯過了一件非常簡單的事情嗎?我輸入aa或AA或c或C,並且它不會進入if語句。任何想法爲什麼?程序沒有進入if語句
while(play){
String answer;
Scanner input = new Scanner(System.in);
System.out.println("Please select an option");
answer = input.nextLine();
answer = answer.toUpperCase().trim();
System.out.println(answer);
if(answer == "AA"){
System.out.println("Have fun!");
System.out.println("Enter player 1's name");
Player player1 = new Player(input.nextLine());
System.out.println("Enter player 2's name");
Player player2 = new Player(input.nextLine());
System.out.println(player1.getName());
System.out.println(player1.getCash());
}
else if (answer == "C"){
play = false;
System.out.println("Thanks for playing");
}
}
埃利奧特具有更快的手指比我... – ajb 2014-11-14 20:17:23