1Z0-811 Control Flow and Loops Practice Question
Exhibit
Refer to the exhibit.
int sum = 0;
for (int i = 1; i <= 10; i++) {
if (i % 3 == 0) {
break;
}
sum += i;
}
System.out.println(sum);What is the value of sum printed?
int sum = 0;
for (int i = 0; i < 3; i++) {sum = sum + i;
}
System.out.println(sum);
⚠ Common exam trap
Oracle often tests the off-by-one error where candidates mistakenly include the final value (i=3) or start counting from 1 instead of 0, leading to incorrect sums like 6 or 1.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
3
The loop initializes sum to 0 and iterates i from 0 to 2 inclusive. In the first iteration, sum = 0 + 0 = 0; second iteration, sum = 0 + 1 = 1; third iteration, sum = 1 + 2 = 3. After the loop, sum is printed, so the output is 3. Option C is correct.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
6
Why it's wrong here
Would be sum if break at i=4.
- ✗
0
Why it's wrong here
Not correct.
- ✓
3
Why this is correct
The value 3 is printed because the code correctly implements an arithmetic operation or a loop that iterates precisely three times. For instance, if a `for` loop is initialised to `i = 0` and its condition is `i < 3`, the loop body will execute for `i = 0, 1, 2`, resulting in three increments to the `sum` variable. This satisfies the constraint of the loop's termination condition accurately determining the final accumulated value.
- ✗
1
Why it's wrong here
Only first iteration.
Go deeper
Related to this question
About these practice questions
This 1Z0-811 question is part of Courseiva's 481-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.