Question 218 of 481
1Z0-811 Arrays and Methods Practice Question
Exhibit
public class Example {
public static void main(String[] args) {
int[] nums = {1, 2, 3};
int[] result = process(nums);
System.out.println(result[0]);
}
public static int[] process(int[] input) {
int[] output = new int[input.length];
for (int i = 0; i < input.length; i++) {
output[i] = input[i] * 2;
}
return output;
}
}Refer to the exhibit. What is the output?
⚠ Common exam trap
Oracle often tests the interaction between `break` and loop counters, where candidates mistakenly count all array elements or forget that `break` exits immediately without completing the remaining iterations.
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 code initializes an array `arr` with values {1, 2, 3}. The for loop iterates over the array, and the `if` condition checks if the current element equals 2. When `arr[1]` (value 2) is encountered, the `break` statement exits the loop immediately. The loop executes only twice (for indices 0 and 1), so the counter `count` is incremented twice, resulting in output 2.
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
This would be the output if the loop completed all three iterations without breaking, but the break statement exits the loop when the element equals 2, so only two iterations occur.
- ✓
2
Why this is correct
Correct: The loop increments count for elements 1 and 2 (indices 0 and 1). When arr[1] (value 2) is encountered, the break statement exits the loop, so count is 2.
- ✗
1
Why it's wrong here
This would be the output if only the first element matched the condition and the loop then broke, but the condition checks for value 2, which is the second element, so count increments twice before breaking.
- ✗
0
Why it's wrong here
This would be the output if no iterations occurred or if the condition never matched, but the loop iterates twice and the condition matches at index 1, so count is incremented twice.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jun 30, 2026
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.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.