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:00
Laire writes a letter to her grandmother, in which she describes an amusement park she visited last week. she adds pictures of that place in her letter. which feature of a word processing program will claire to remove unwanted parts of the pictures?
Answers: 3
question
Computers and Technology, 23.06.2019 12:50
Which syntax error in programming is unlikely to be highlighted by a compiler or an interpreter? a variable name misspelling a missing space a comma in place of a period a missing closing quotation mark
Answers: 1
question
Computers and Technology, 24.06.2019 10:00
Each time you save a document, you will need to type in the file type in which it should be saved you can select the save button to save it with the same file name if it has been previously saved you will need to select the location to save the file you will need to use the save as dialog box
Answers: 1
question
Computers and Technology, 24.06.2019 15:00
Universal windows platform is designed for which windows 10 version?
Answers: 1
You know the right answer?
Consider the following field and incomplete method of some class. The method calcTotal is intended t...
Questions
Questions on the website: 13722363