基本上我有这个代码,我想让它这样,当awnserF = awnser6
时,两个玩家都输了。我不知道该怎么做。我想要完成这一点,同时保持这样一个事实,即当awnserF>awnser6
玩家1获胜时。
System.out.println(" ");
if (awnserF > awnser6) {
System.out.println("PLAYER ONE wins!");
}
else {
System.out.println("PLAYER TWO wins!");
}
if (awnserF = awnser6) {
System.out.println("You both lose!");
}
试试这个
System.out.println(" ");
if (awnserF>awnser6){
System.out.println("PLAYER ONE wins!");
}
else if (answerF<answer6) {
System.out.println("PLAYER TWO wins!");
}
else {
System.out.println("You both lose!");
}
}
}
比较时要使用==
。单个=
操作符用于为变量赋值。
你也可以使用and if…其他的如果……其他结构。
if (awnserF > awnser6){
System.out.println("PLAYER ONE wins!");
}
else if (awnserF < awnser6) {
System.out.println("PLAYER TWO wins!");
}
else { // (awnserF == awnser6)
System.out.println("You both lose!");
}
您正在使用=
来检查选择是否相等,当它实际上应该是==
。这应该可以工作。
if(awnswerF == awnser6){
System.out.println("You both lose!")
}
else if(awnserF > awnser6){
System.out.println("PLAYER ONE wins!")
}
else{
System.out.println("PLAYER TWO wins!")
}
但说真的,谁想玩一个双方都输的游戏呢;)
如何使用if,elseif,else
结构:
if (awnserF>awnser6){
System.out.println("PLAYER ONE wins!");
}
else if(awnserF==awnser6){
System.out.println("You both lose!");
}
else{
System.out.println("PLAYER TWO wins!");
}
注意:有2个==
用于比较,1个=
用于赋值