不确定我是否在这里错过了一些东西。有两个球队,我想回到"蓝鸟",但我一直在少年时代保持无效。有什么想法会导致这件事?
谢谢
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;
}
}
}
您必须在方法末尾返回字符串类型。
所以尝试替换
else{ winner=null; }
return winner;