193k views
1 vote
What is the output by the code below?

int counter = 0;
for (int c = 0; c < 10; c = c + 2)
{
counter++;
}
System.out.println(counter);
a. 5
b. 6
c. 7
d. 10

User Elver Loho
by
8.8k points

1 Answer

2 votes

Final answer:

The output of the code is 5.

Step-by-step explanation:

The output of the code is 5.

The code initializes a variable named counter to 0. Then, it uses a for loop to iterate over the values of a variable named c, starting from 0 and increasing by 2 on each iteration until it reaches 10. Inside the loop, the counter variable is incremented by 1. So, the loop will run 5 times (0, 2, 4, 6, 8), and the final value of the counter will be 5.

Therefore, the correct option is a. 5.

User Tony Vincent
by
8.2k points