# ArrayOutOfBoundsException in Bluej?

Printable View

• 09-06-2011, 02:07 PM
chirikoo
ArrayOutOfBoundsException in Bluej?
We've been asked to create this SudokuChecker program, and whenever I enter a valid solution, this error keeps popping up.
This only happens when I check the regions(the individual 3x3 grids in the 9x9)
Here is my code:
Quote:

public boolean checkRegions()
{
int startColumns = 0;
int finalColumns = 3;
int startRows = 0;
int finalRows = 3;
for(int y=0; y<3; y++)
{
for(int z=0; z<3; z++)
{
boolean presentNumber[] = new boolean[9];
for(int j=0; j<9; j++)
{
presentNumber[j] = false;
}
for(int rows=startRows; rows<finalRows; rows++)
{
for(int columns=startColumns; columns<finalColumns; columns++)
{
for(int k=0; k<9; k++)
{
if(Sudoku[rows][columns] == k+1 && presentNumber[k])
{
return false;
}
else if(Sudoku[rows][columns] == k+1 && !presentNumber[k])
{
presentNumber[k] = true;
}
}
}
}
startColumns += 3;
finalColumns += 3;
}
startRows += 3;
finalRows += 3;
startColumns += 3;
finalColumns += 3;
}
return true;
}
Error message pops up at the bolded part.
Any help?
• 09-06-2011, 02:44 PM
JosAH
Re: ArrayOutOfBoundsException in Bluej?
Print out the values for startColumns, finalColumns, startRows and finalRows at each loop pass; you are forgetting to reset the rows/columns (I can't exactly see which ones without proper indentation).

kind regards,

Jos