0
所以我的問題是我試圖做一個非常簡單的程序來刷新我可怕的編碼技能,但我遇到了一個我不明白的問題。該程序應該回答「是」並打印「耶」,只是爲了檢查它是否工作,但它不起作用。所以我想知道我做錯了什麼。掃描nextLine()似乎並沒有改變字符串
public class main {
/**
* @param args
*/
public static void main(String[] args) {
int playerTroops, computerTroops;
String teamName, computerName = "Orcs", answer;
Scanner listener = new Scanner(System.in);
System.out
.println("Welcome to the Battle Grounds, where you are responsible for winning a war \nAre you ready? \nYes or No");
answer = listener.nextLine();
if (answer == "Yes")
System.out.println("Yayy");
else
System.out.println("Why");
}
}
哦,謝謝你的工作 – user2113591 2013-02-27 02:12:27
@ user2113591歡迎來到SO。不要忘記[接受](http://meta.stackexchange.com/a/5235/186652)回答是否可以解決您的問題(時限過後)。 – Pshemo 2013-02-27 02:24:29