The Artima Developer Community
Sponsored Link

Java Answers Forum
Array Problem

1 reply on 1 page. Most recent reply: May 10, 2007 7:58 AM by Vincent O'Sullivan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Jonathan Davids

Posts: 11
Nickname: jonat
Registered: Mar, 2007

Array Problem Posted: May 10, 2007 2:38 AM
Reply to this message Reply
Advertisement
Hello,
I am a bit confused on why this code is not working. I have a two-dimensional array where I store String elements. I call it String [][] DixElements. Then I have another one-dimensional array, String []backArray, where I copy-backwards each row of the two-dimension array starting from a row before the last for further use.


public String [] BStorage() {
int size = DixElements.length; //two-dimensional array (globally defined)
for(int b = size-1 ; b > 0; b-- ) {
backArray = new String [DixElements[b-1].length]; //backArray is a one-dimensional array and it is globally defined

for (int d = 0; d < backArray.length; d++) {
backArray[d] = DixElements[b][d];
System.out.println(backArray[d]);

}
}

return backArray;
}




If I run it, I always get all the rows except the first row but I wanted to get all the rows except the last row.

Thanks for the help.

Jonat


Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: Array Problem Posted: May 10, 2007 7:58 AM
Reply to this message Reply
I've only had a quick glance but it looks like b is the (zero based) index of the row you're printing and that you're printing from row = size - 1 (the last row) down to row = 1 (the second row). Therefore the row not being printed is the first row. If that's the case then loop from row = size - 2 (the second-last row) down to row = 0 (the first row). (size >= 2)

Flat View: This topic has 1 reply on 1 page
Topic: Array Problem Previous Topic   Next Topic Topic: java

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use