Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help with arrays  RSS feed

 
Timothy Han
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

What is wrong with my code here?


 
Ramya R Subramanian
Ranch Hand
Posts: 182
18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Index of an array starts with 0. Your array is of length 3. So the indexes of your array can be 0,1,2. In line 16, you try to access the index 3 ,which does not exist so it throws an ArrayIndexOutOfBoundsException.
lines 17,20,21 will throw ArrayIndexOutOfBoundsException for the same reason.

This will be helpful - https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
 
Timothy Han
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much!!! It worked!!!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!