Limited access

Upgrade to access all content for this subject

The Athlete class is used to keep track of an athlete’s name, sport, ranking, and age. Assume that there are accessor methods named getName(), getSport(), getRank(), and getAge() in the Athlete class to retrieve this information from an Athlete object.

Which segment of code will print the highest age of all golfers in the athletes array?

Athlete[] athletes = // Assume that this array is full of Athlete objects
A
int max=0, maxI=-1;
for (int i=0; i<athletes.length; i++)
{
    if(athletes[i].getSport().equals("golf") && athletes[i].getAge() > max)
        maxI = i;
}
System.out.println(maxI);
B
int max=0, maxI=-1;
for (int i=0; i<athletes.length; i++)
{
    if(athletes.getSport().equals("golf") && athletes.getAge() > max)
        max = athletes.getAge();
}
System.out.println(max);
C
int max=0, maxI=-1;
for (int i=0; i<athletes.length; i++)
{
    if(athletes[i].getSport().equals("golf") && athletes[i].getAge() > max)
        max = athletes[i].getAge();
}
System.out.println(max);
D
int max=0, maxI=-1;
for (int i=0; i<athletes.length; i++)
{
    if(athletes.get(i).getSport().equals("golf") && athletes.get(i).getAge() > max)
        max = athletes.get(i).getAge();
}
System.out.println(max);
E
int max=9999, maxI=9999;
for (int i=0; i<athletes.length; i++)
{
    if(athletes[i].getSport().equals("golf") && athletes[i].getAge() > max)
        max = athletes[i].getAge();
}
System.out.println(max);
Select an assignment template