I've been trying to build a sudoku, starting with a 9x9 array that ensures no numbers in a given column nor row are the same (ie sudoku without the 3x3 boxes). I've set my code as seen below, but I keep running into a runtime error that I think stems from the do-while statement where the array won't finish filling. However, if I add 10 to the new randomized number (within the do-while statement) the array will finish filling. I've also created a lengthy "check" method that checks whether the current cell is the same as any of the others in that column or row and returns true only if the number is original. I have not included that method for simplicity. Is there something I'm missing?
import java.util.Random;
public class S9x9 {
public static void main (String[] args){
int [][] nines = new int [9][9];
Random rand = new Random();
for (int i = 0; i < nines.length; i++) {
for (int j = 0; j < nines.length; j++) {
nines[i][j] = rand.nextInt(9) + 1;
if (!(check(nines,i,j))) {
do
nines[i][j] = rand.nextInt(9) + 1;
while (!(check(nines, i, j)));
}
System.out.print(nines[i][j] + " ");
}
System.out.print("\n");
}
}
}