• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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];
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic