I'm a student, this is an exercise and this is the goal of this method: This method should return the first element of the Athlete array that has a name matching the name parameter. If there is no matching Athlete, return null.
For some reason, i'm getting this error,
TestAthletes.java:15: error: missing return statement
}
This is my code:
public class TestAthletes{
public static Athlete findAthleteByName(Athlete[] athletes, String name){
for(int i=0; i<athletes.length; i++){
if(name.equals(athletes[i].getName()))
return athletes[i];
else
return null;
}
}
}
Can't figure out what the problem is.