Computers and Technology

Please help me with this coding problem :) 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

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 02:00, rah45
Which of the following is not a source of sustainable raw materials? a) coal mine b) flick of sheep c) cotton plantation d) line forest.
Answers: 2
image
Computers and Technology, 24.06.2019 08:30, ladybuggirl400
@josethesolis i need can anyone text me and follow me
Answers: 1
image
Computers and Technology, 24.06.2019 11:00, abolton04
In three to five sentences, describe how you can organize written information logically and sequentially
Answers: 1
image
Computers and Technology, 25.06.2019 01:30, jeff6284
Ashort circuit locator should be periodically run along the cords used in a shop to check for shorts and open circuits. a.)true b.)false
Answers: 2
Do you know the correct answer?
Please help me with this coding problem :) Consider the following field and incomplete method of so...

Questions in other subjects:

Konu
Mathematics, 06.01.2020 17:31