Study Help On 2D Arrays

Hey, so I have a big test on 2D Arrays coming up in my Computer Science class, and we went over this worksheet and I’m confused on a particular question:

int[][] arr = {{31, 9, 29, 67, 74, 100, 49}, {65, 23, 72, 83, 28, 36, 82}, {2, 3, 4, 5, 6, 7, 8}};

The question is: What is the output for System.out.println(arr[3*2][6])?

My teacher is out sick for the rest of the week so I can’t ask her, so I’m asking you guys: Why isn’t this just a runtime error?

What language is this? What happens if you try to run the code provided?

It’s just in Java, and it gives me an IndexOutOfBounds exception, but it doesn’t take that as the correct answer.

That is what I would expect too. [6][6] is indeed out of bounds.

I’m not really sure why it doesn’t accept it as the correct answer. I’ll email my teacher and ask her, but I’m not sure when she’ll respond. Thank you for the help though!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.