n is equal to 2 when its loop is over, but by the last "if" statement it's somehow 3. )
can not figure out where it's changing.
because the last if condition isn't being met the for loop keeps going instead of returning true (for(int i=0;i<Board[i].length;i++)) and ) get an out of bounds exception.
so two questions -
- can u spot where n changes?
- how come the for loop with I keeps going despite the condition being met?
Board[i].length=3and the loop just keeps going and gives me an out of bounds exception instead of exiting the for loop and returning me the false after it.
public boolean ColChecker() {
int n=0;
// create boolean array and set all values to false
boolean[] isExist = new boolean[10];
for(int i=0;i<isExist.length;i++)
isExist[i]=false;
//loop over columns and test using whosThereCol method
for(int i=0;i<Board[i].length;i++) {
for(int col=0;col<Board[0][0].getLength();col++) {
for(n=0;n<Board.length;n++)
Board[n][i].whosThereCol(col,isExist);
//if array still has missing values, column incomplete - return false
for(int j=1;j<10;j++)
if(!isExist[j])
return false;
//if no missing values, initialize array to false values for next iteration of for loop
for(int j=1;j<10;j++)
isExist[j]=false;
// "if" statement checks if this is the last column in the last square, if so, we passed all the tests. return true
if(i+1==Board[0].length&&col+1==Board[0][0].getLength()&&n+1==Board.length)
return true;
}
}
return false;
}
