1 回答

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超9個(gè)贊
== 測(cè)試參考相等性和
.equals() 值相等的測(cè)試。
因此,將字符串與equals()方法進(jìn)行比較:
if (userAnswer.equals(compAnswer)) {}
所以你的代碼會(huì)像這樣:
if (userAnswer.equals(compAnswer)) {
System.out.println("Huh. A tie. That was... disappointing.");
win = 2;
} else if ("rock".equals(compAnswer)) {
{
if ("paper".equals(userAnswer)) {
System.out.println("Curses! I threw rock and lost!");
win = 0;
} else if ("scissors".equals(userAnswer)) {
System.out.println("Hah! I threw rock and crushed your scissors!");
win = 1;
}
}
} else {
System.out.println("...You cheater! That's not a legal throw! Off to the fire and brimstone with you!");
}
添加回答
舉報(bào)