• Post Reply Bookmark Topic Watch Topic
  • New Topic

Multidimentional Array of type String  RSS feed

 
Rubbal Bhusri
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the error in following code ?
why the output shows : Array-index-out-of-bound, when it is not ?
The code is :


 
manish ghildiyal
Ranch Hand
Posts: 136
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...in first look it seems that

for(int num = 0; num <= 3; num++){
for(int num1 = 0; num <= 3; num1++){

.................must be

for(int num = 0; num <= 3; num++){
for(int num1 = 0; num1 <= 3; num1++){
 
Rubbal Bhusri
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What a silly mistake I did ! Thank you so much for being more than a compiler because even my compiler didn't give me exact explanation of this mismatch.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rubbal Bhusri wrote:What a silly mistake I did ! Thank you so much for being more than a compiler because even my compiler didn't give me exact explanation of this mismatch.

Yes it did: it gave you an ArrayIndexOutOfBoundsException. It was you who assumed that it couldn't be right.

Winston
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't forget that System.out.println() can be your best friend. When you think "There is NO WAY the index can be out of bounds", print out what the index IS on each iteration, and you'll quickly see that your index got to '4'.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!