Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q5 of 15
Java - Arrays
What will be the output of this code?
int[] arr = {1, 3, 5};
for(int i = arr.length - 1; i >= 0; i--) {
  System.out.print(arr[i]);
}
A135
B531
CError
D1 3 5
Step-by-Step Solution
Solution:
  1. Step 1: Understand loop direction

    The loop starts from the last index and goes backward to 0, printing elements in reverse order.
  2. Step 2: Determine printed sequence

    Elements printed are 5, then 3, then 1 without spaces.
  3. Final Answer:

    531 -> Option B
  4. Quick Check:

    Reverse traversal prints elements backward [OK]
Quick Trick: Loop backward to print array in reverse [OK]
Common Mistakes:
  • Confusing forward and backward loops
  • Expecting spaces between numbers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes