my first question here, am new to coding and this is my first semester of a CS degree, got this assignment, a sudoku that i have to loop through and check if the user has filled the whole thing, an empty squares equals zero. the test runs only work if the clear method to clear a certain square isnt invoked. here is ny code
public boolean allSet(){
for(int row = 0; row < grid.length; row ){
for(int col = 0; col <grid[row].length; col ){
if(grid[row][col] != 0){
return true;
}
}
}
return false;
}
CodePudding user response:
you almost had it! you were quitting when you found one filled in square instead of checking all the squares. What you want to do instead is quit if you find one empty square because this means it is not all set.
public boolean allSet(){
for(int row = 0; row < grid.length; row ){
for(int col = 0; col <grid[row].length; col ){
if(grid[row][col] == 0){
return false;
}
}
}
return true;
}
This should do the trick.