我不确定我是否遗漏了一些东西。有两个团队,我想回到“Blue Jays”,但我只是在我的JUnit中保持null。可能导致这种情况的任何想法?
谢谢
public String winner(String team1, String team2) {
String winner = null;
for(Game g: games) {
if ((g.getTeamOneName().equals(team1) && g.getTeamTwoName().equals(team2))
|| g.getTeamOneName().equals(team2) && g.getTeamTwoName().equals(team1)) {
if (g.getTeamOneScore() > g.getTeamTwoScore()) {
winner = g.getTeamOneName();
}
else if (g.getTeamOneScore() < g.getTeamTwoScore()) {
winner = g.getTeamTwoName();
}
else if (g.getTeamOneScore() == g.getTeamTwoScore()) {
winner = "tie";
}
else {
winner = null;
}
}
}
答案 0 :(得分:-2)
您必须在方法的末尾返回String类型。
所以尝试替换
else{ winner=null; }
带
return winner;