Free Version
Difficult

# One Mile Run Times (2-Dimensional Array)

APCSA-EVPKYP

A gym teacher requires each student to run one-mile several times throughout the year. Each run time (in seconds) is recorded in a two-dimensional array, where each row is a student and the columns are the run times (in chronological order) for that student. In order to see if each individual student has improved throughout the year, the gym teacher wants to compare the student’s last run time to their first run time. A negative difference means that the student has improved their run time throughout the year.

Consider this method signature.

/*
* Prints the difference in the first and last run times for each
* student and returns the cumulative difference for all students.
* @param runTimes = 2-dim array of run times (each row is a student
* and the columns are the student's run times.
* @return the cumulative difference in last and first run times.
*/

public static int evaluateRunTimes(int[][] runTimes)
{
/*  Place your code here  */
}


Which of the following segments of code would perform this function?

I.


int totalDiff = 0;
for (int r=0; r<runTimes.length; r++)
{
int runDiff=0;
for (int c=1; c<runTimes[r].length; c++)
{
runDiff = runTimes[r][c] - runTimes[r][c-1];
}
totalDiff += runDiff;
System.out.println(runDiff);
}


II.


int totalDiff = 0;
for (int r=0; r<runTimes.length; r++)
{
int runDiff = runTimes[r][runTimes[r].length-1] - runTimes[r][0];
totalDiff += runDiff;
System.out.println(runDiff);
}


III.

int totalDiff = 0;
for (int r=0; r<runTimes.length; r++)
{
int firstTime = runTimes[r][0];
int lastTime=0;
for (int c=0; c<runTimes[r].length; c++)
{
lastTime = runTimes[r][c];
}
totalDiff += (lastTime - firstTime);
System.out.println(lastTime - firstTime);
}

A

I and II only.

B

I and III only.

C

II and III only.

D

II only.

E

I only.