java - Array index out of bounds - converting 2d to 1d -
I'm not really sure why I'm getting an array index out of bounds exception. For my understanding, my double array is of 3 sizes, so the index goes from 0 - 2. I have the qualification method, I try to calculate the number of inversions within my double array, where an inverse The pair of blocks I and j is l & lt; Jammu, but after Jammu, when the row-main sequence is considered on the board, I try to do this by converting my 2D array into 1d array so that I cross through the 1d array to count all the inversions. Can do If the inversion is also (inside the weird numbered board of size), then 8 puzzle boards are able to solve. For loops, only my length of the array is counted, so I'm not completely sure how I am getting an array index outside the exception of the barriers
thanks in advance! Every answer prevents me from making the same mistakes in the future and prevents me.
int n = 3; Fixed int [] [] copy; // Build a board with an N-by-N array of blocks / (where block [i] [j] = block in line I, column j) Public board (int [] [] block) {blocks = new int [N] [n]; // creates an array of size N / Random number generates 0 only for unique # 0 makes ArrayList - the list is used to stop repeating the list & lt; Integer & gt; RandomList = New Arrielist & lt; & Gt; (); For (int i = 0; i
You have a typo in the inner loop of the code> usable :
(int j = 0; i & lt; copy [i]. Length; j ++) should be {^ | j must be :
for (int j = 0; j & lt; Copy [i] Length; J ++) {
Comments
Post a Comment