1Z0-811 Java Basics and Syntax Practice Question
Exhibit
Refer to the exhibit.
public class LoopTest {
public static void main(String[] args) {
int count = 0;
for (int i = 0; i < 5; i++) {
if (i % 2 == 0) {
continue;
}
count++;
}
System.out.println(count);
}
}What is the value printed?
⚠ Common exam trap
Oracle often tests the off-by-one error where candidates miscount loop iterations or confuse the final value of the loop variable with the sum, leading them to pick 3 (the value after the loop exits) instead of 2 (the value when the condition fails).
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
✓
2
The while loop condition is `x < 2`, so the loop executes while x is less than 2. Initially x=0. In the first iteration, x becomes 1; in the second, x becomes 2. After the second iteration, x=2, the condition `2 < 2` is false, so the loop stops. The code prints the value of x, which is 2 after the loop exits.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
3
Why it's wrong here
i=5 not reached.
- ✗
5
Why it's wrong here
Continue skips even numbers.
- ✓
2
Why this is correct
Only i=1 and i=3 increment count.
- ✗
0
Why it's wrong here
Count increments for odd numbers.
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.