1Z0-829 Controlling Program Flow Practice Question
What is the output of the following code?
```java
int i = 5;
while (i > 0) {System.out.print(i + " "); i--;
}
```
⚠ Common exam trap
The trap here is that candidates might think the loop stops before printing the last value (1) or that the decrement happens before printing, leading them to choose options C or D.
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
✓
5 4 3 2 1
The while loop runs as long as i > 0. Starting with i = 5, each iteration prints the current value of i followed by a space, then decrements i by 1. The loop stops when i becomes 0, so the output is '5 4 3 2 1 '.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
5 4 3 2 1
Why this is correct
Correct countdown from 5 to 1.
- ✗
The code does not compile because i is not declared final.
Why it's wrong here
Variable i can be modified.
- ✗
5 4 3 2
Why it's wrong here
The loop prints 1 as well.
- ✗
4 3 2 1
Why it's wrong here
Initial i=5 is printed first.
Go deeper
Related to this question
About these practice questions
One of 513 original 1Z0-829 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.