1Z0-829 Controlling Program Flow Practice Question
What is the output of the following code? int i=5; do { System.out.print(i); i--; } while(i>0);
⚠ Common exam trap
The trap here is that candidates often mistakenly think the loop prints 0 because they overlook that the condition is checked after the body executes, and the loop exits when i becomes 0 without printing it.
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
✓
54321
The do-while loop executes the body first, printing the current value of i (5), then decrements i to 4. The loop continues while i > 0, so it prints 5, 4, 3, 2, 1, and stops when i becomes 0, as the condition i > 0 is false. This results in the output "54321".
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
54321
Why this is correct
The loop prints each number from 5 down to 1.
- ✗
Compilation error
Why it's wrong here
The code is syntactically correct.
- ✗
543210
Why it's wrong here
It does not print 0 because the condition is checked after decrement.
- ✗
5432
Why it's wrong here
It also prints 1.
Go deeper
Related to this question
About these practice questions
This 1Z0-829 question is part of Courseiva's 513-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-829 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-829 exam.