subject

Consider the following field and incomplete method of some class. The method calcTotal is intended to return the sum of all values in vals. private int[] vals;

public int calcTotal()
{
int total = 0;

/* missing code */

return total;
}
Which of the code segments shown below can be used to replace /* missing code */ so that calcTotal will work as intended?

I.
for (int i : vals)
{
total += i;
}
II.
for (int pos = vals. length; pos > 0; pos--)
{
total += vals[pos];
}
III.
int pos = 0;
while (pos < vals. length)
{
total += vals[pos];
pos++;
}

I only
II only
I and III
II and III
III only

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 04:31
Acloud service provider uses the internet to deliver a computing environment for developing, running, and managing software applications. which cloud service model does the provider offer? a. iaas b. caas c. maas d. paas e. saas
Answers: 1
question
Computers and Technology, 23.06.2019 12:30
Animations and transitions are added from the
Answers: 1
question
Computers and Technology, 23.06.2019 19:30
Anul 2017 tocmai s-a încheiat, suntem trişti deoarece era număr prim, însă avem şi o veste bună, anul 2018 este produs de două numere prime, 2 şi 1009. dorel, un adevărat colecţionar de numere prime, şi-a pus întrebarea: “câte numere dintr-un interval [a,b] se pot scrie ca produs de două numere prime? “.
Answers: 1
question
Computers and Technology, 23.06.2019 21:40
Draw the resistor’s voltage and current phasors at t=15ms. draw the vectors with their tails at the origin. the orientation of your vectors will be graded. the exact length of your vectors will not be graded.
Answers: 2
You know the right answer?
Consider the following field and incomplete method of some class. The method calcTotal is intended t...
Questions