1Z0-803 · Question #179
Given: What is the result?
The correct answer is A. 6 7 8. The program executes a 'for' loop that initializes an integer 'i' to 6, continues as long as 'i' is strictly less than 9, and prints the value of 'i' in each iteration.
Question
Given:
What is the result?
Exhibit
Options
- A6 7 8
- B7 8 9
- C0 1 2
- D6 8 10
- ECompilation fails
How the community answered
(15 responses)- A73% (11)
- B7% (1)
- D13% (2)
- E7% (1)
Why each option
The program executes a 'for' loop that initializes an integer 'i' to 6, continues as long as 'i' is strictly less than 9, and prints the value of 'i' in each iteration.
The 'for' loop starts with 'i = 6', prints '6'. It then increments 'i' to '7', prints '7'. Finally, 'i' becomes '8', prints '8'. When 'i' increments to '9', the condition 'i < 9' is false, and the loop terminates, resulting in the output "6 7 8".
This choice would require the loop to start printing from '7' and continue to '9', which would imply different loop bounds (e.g., 'for (int i = 7; i < 10; i++)').
This choice represents numbers far outside the likely range of the loop's starting point (e.g., 'for (int i = 0; i < 3; i++)').
This choice shows numbers with an increment of 2 (6, 8, 10), which would require a step increment (e.g., 'i += 2') and potentially different loop bounds.
The code structure described (a simple 'for' loop printing integers) is syntactically correct and will compile without errors.
Concept tested: for loop iteration and bounds
Source: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html
Topics
Community Discussion
No community discussion yet for this question.
