1Z0-811 Control Flow and Loops 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) {
continue;
}
count++;
}
System.out.println(count);
}
}int count = 0;
for (int i = 0; i < 5; i++) {
if (i == 2) {continue;
}
count++;
}
System.out.println(count);
What is the output of the program?
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
✓
4
The loop iterates from i=0 to i=4. When i equals 2, the continue statement skips the rest of the loop body, so the increment of count is not executed for i=2. For the remaining four iterations (i=0,1,3,4), count is incremented, resulting in a final value of 4. Option B is incorrect because the loop code is syntactically valid and compiles without error. Option C would be correct if a break statement were used instead of continue. Option D is incorrect because the loop runs the full 5 iterations, incrementing count 4 times.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
4
Why this is correct
The program produces 4 because Java's integer division truncates any decimal part, satisfying the constraint that arithmetic operations involving two integer operands yield an integer result. For instance, an expression like `9 / 2` evaluates to 4, discarding the `.5`. This mechanism ensures the output is a whole number, precisely reflecting the quotient without rounding.
- ✗
The loop does not compile.
Why it's wrong here
The code compiles and runs fine.
- ✗
5
Why it's wrong here
If continue were break, count would be 2, but it's continue.
- ✗
2
Why it's wrong here
This would be the result if continue caused early termination like break.
Go deeper
Related to this question
About these practice questions
Courseiva writes every 1Z0-811 question from scratch — 481 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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.