What would this be?
Consider the following incomplete method:
public int total(int[] scores)
// precondition: The sentinel -999 occurs
// somewhere in scores
{
int k = 0;
int sum = 0;
while (scores[k] != -999)
{
<program statements>
}
return sum;
}
Method total is intended to return the sum of the integers in parameter scores, beginning with the first integer in scores and up to, but not including the sentinel ?999 (which occurs somewhere in scores). Which of the following code segments could be used to replace <program statements> so that total will work as intended?
Consider the following incomplete method:
public int total(int[] scores)
// precondition: The sentinel -999 occurs
// somewhere in scores
{
int k = 0;
int sum = 0;
while (scores[k] != -999)
{
<program statements>
}
return sum;
}
Method total is intended to return the sum of the integers in parameter scores, beginning with the first integer in scores and up to, but not including the sentinel ?999 (which occurs somewhere in scores). Which of the following code segments could be used to replace <program statements> so that total will work as intended?