subject

Consider the following code segment:

int counter = 5;
int sum = 0;
while(counter < 10)
{
sum+= counter;
counter+=2;
}

Which of the following for loops would return the same value if System. out. println(sum) were printed?

I.

int sum = 0;
for(int i = 0; i < 3; i++)
{
sum += i;
}

II.

int sum = 11;
for(int i = 0; i < 5; i ++)
{
sum+=i;
}

III.

int sum = 0;
for(int i = 5; i < 10; i+=2)
{
sum +=i;
}

IV.

int counter = 5;
int sum = 0;
for(int i = counter; i < 10; i+=2)
{
sum+= counter;
}

III only

II, III and IV

II only

II and III

III and I

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 18:00
When is it appropriate to use an absolute reference
Answers: 1
question
Computers and Technology, 23.06.2019 03:10
Acomputer has a two-level cache. suppose that 60% of the memory references hit on the first level cache, 35% hit on the second level, and 5% miss. the access times are 5 nsec, 15 nsec, and 60 nsec, respectively, where the times for the level 2 cache and memory start counting at the moment it is known that they are needed (e.g., a level 2 cache access does not even start until the level 1 cache miss occurs). what is the average access time?
Answers: 1
question
Computers and Technology, 23.06.2019 06:20
Which text function capitalizes the first letter in a string of text? question 10 options: upper capital first proper
Answers: 1
question
Computers and Technology, 24.06.2019 20:00
Avirus enters a computer or network as code embedded in other software directly from another computer
Answers: 1
You know the right answer?
Consider the following code segment:

int counter = 5;
int sum = 0;
while(cou...
Questions
question
Mathematics, 13.09.2019 23:10
question
Mathematics, 13.09.2019 23:10
question
Mathematics, 13.09.2019 23:10
question
Chemistry, 13.09.2019 23:20
question
Mathematics, 13.09.2019 23:20