Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

:confused: merge/covert array Part II :confused:

 
Paul LaBrier
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to take all of the data in a double subscripted array, except for the first column, and add it into a new single subscripted array. I HAVE to do it by code, I cannot simply retype the data into the new array. I created the following as a test case and it works except for the fact that it throws an exception upon execution. I added test output to see where the problem is, but I am not finding it. I am sure it something very simple.
The error I get is:
java.lang.ArrayIndexOutOfBoundsException: 3
at ArrayCopyDemo.main[Compiled Code}
Any help will be appreciated,
Paul
[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ August 12, 2002: Message edited by: Dirk Schreckmann ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for (int row = 0; row <= students; row++)
What is the initial value of row? What is the final value of row? If students = 3, how many different values of row do you have in this loop?
 
Paul LaBrier
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BINGO! Thanks, I knew it was something like that, but after staring at it a while it was all going fuzzy.
You know, if arrays start their cointing at 0, why does array.length start with 1? Seems a bit inconsistant to me.
Paul
 
Paul LaBrier
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BINGO! Thanks, I knew it was something like that, but after staring at it a while it was all going fuzzy.
You know, if arrays start their cointing at 0, why does array.length start with 1? Seems a bit inconsistant to me.
Paul
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because it is legal and possible to have an empty array -- an array whose length is 0:
String[] none = new String[0];
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,
Please note that you can preserve the formatting of code by surrounding it with the [code] and [/code] UBB Tags. It can make it a lot easier to read.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic