1 回答
TA贡献1853条经验 获得超9个赞
== 测试参考相等性和
.equals() 值相等的测试。
因此,将字符串与equals()方法进行比较:
if (userAnswer.equals(compAnswer)) {}
所以你的代码会像这样:
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!");
}
添加回答
举报