Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 8: 2D Array
Start Practice TestPractice Test
About Exam
medium Solved by 1 students

2D Array Traversal Error

< Prev
Next >

What is the result when the following code segment is executed?

double[][] prices = {{0.99, 1.29, 1.49}, {0.79, 0.99}};
for(int i = 0; i < prices.length; i++){
   for(int j = 0; j < prices[0].length; j++){
      System.out.print(prices[i][j] + " ");
   }
   System.out.println();
}
A

Compilation error due to mismatched row lengths.

B

ArrayIndexOutOfBoundsException occurs because prices[0].length is used for all rows, but the second row has fewer elements.

C

NullPointerException due to uninitialized elements.

D

No error; it correctly prints all elements.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question
Mark for review

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|