• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array "outofbounds" message  RSS feed

 
Karl Beaudry
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So my issue is with the start of my code, right when i try to execute the program and input the first row of numbers. I am trying to get this step by step like I always do. Compile move along to the next method. Anyways I keep getting that I am out of bounds, what have i done. I have the array set to 4 rows and 4 columns. I want the user to input the four numbers then on to the next row. Well when I input the first 4 numbers it returns an "out of bounds" message for Line:14. why? Also I changed the code to a different way which let me do it two rows of numbers, but same error message. I can give you further details into what I am writing if you need it, but for now I just am trying to figure out this out and move on to the next step. Thanks, Ive just never ran across a out of bounds message before, and it seems to look right to me and compiles fine.

 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you have parentheses around the i?

 
Stefan Evans
Bartender
Posts: 1837
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your indentation doesn't match what the code will actually do.
This is what is currently happening:

On compiling, I get an undefined variable 'i'.


Judging from the code you have posted on the first iteration through the array
a[0][0] --> (succeeds)
a[1][1] --> (array index out of bounds. There is only one element in the array a[1]. a[1][0] would succeed, but a[1][1] won't.
 
Karl Beaudry
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found my issue, re-written. I changed the array (lines 5-9) and added code between lines 14 & 15. Now i am able to enter in numbers for each row and col.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!