Two Laptop Bag*
The moose likes Beginning Java and the fly likes :confused: merge/covert array Part II :confused: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ":confused: merge/covert array Part II :confused:" Watch ":confused: merge/covert array Part II :confused:" New topic
Author

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

Paul LaBrier
Greenhorn

Joined: Apr 08, 2002
Posts: 21
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

Joined: Jan 30, 2000
Posts: 18671
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?


"I'm not back." - Bill Harding, Twister
Paul LaBrier
Greenhorn

Joined: Apr 08, 2002
Posts: 21
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

Joined: Apr 08, 2002
Posts: 21
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

Joined: Jun 06, 2002
Posts: 1056
Because it is legal and possible to have an empty array -- an array whose length is 0:
String[] none = new String[0];


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: :confused: merge/covert array Part II :confused: