我试图告诉 Critter 程序从四个选项中随机选择一种攻击类型;我以为我已经涵盖了我的 return 语句基础,但是我从 drjava 收到“缺少返回语句”错误:
public Attack fight(String opponent) {
int fightChoice = new Random().nextInt(4);
if(fightChoice == 0){
return Attack.ROAR;
} if(fightChoice == 1){
return Attack.POUNCE;
} if(fightChoice == 2){
return Attack.SCRATCH;
} if(fightChoice == 3){
return Attack.FORFEIT;
}
}
知道为什么会这样吗?