Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multidimensional Arrays

 
Aruna Balasuriya
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why following code results a runtime exception

 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's check out what each array contains. Initially:
a1 = {null}
a2 = {{null}, {null}}
a3 = {{{null, null, null}, {null, null, null}, {null, null, null}}, {{null, null, null}, {null, null, null}, {null, null, null}}, {{null, null, null}, {null, null, null}, {null, null, null}}}

a1 then becomes {A}
a2 becomes {{A}, {A}}
a3 becomes {{{A}, {A}}, {{A}, {A}}, {{A}, {A}}}

a3 is now no longer an A[3][3][3] but an A[3][2][1]. As such, there is no a3[2][2]. The highest indexes you can get is a3[2][1][0].
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic