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.
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)