Bird
0
0

What will be the output of the following code?

medium📝 Predict Output Q4 of 15
Java - Arrays
What will be the output of the following code?
int[] numbers = {7, 14, 21};
for(int i = 0; i < numbers.length; i++) {
  System.out.print(numbers[i] + ",");
}
A7 14 21,
B7 14 21
C7,14,21
D7,14,21,
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the loop

    The loop prints each element followed by a comma.
  2. Step 2: Check output format

    Each number is printed with a comma immediately after it, including the last element.
  3. Final Answer:

    7,14,21, -> Option D
  4. Quick Check:

    Comma after every element, including last [OK]
Quick Trick: Prints comma after every element, even last [OK]
Common Mistakes:
  • Assuming no comma after last element
  • Confusing spaces with commas
  • Ignoring loop print statement details

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes