Skip to main content
1 of 2
Simon Forsberg
  • 59.7k
  • 9
  • 160
  • 312

Just a couple of minor things:

  • In Java, { braces should be put at the end of the same line and not on it's own line.

  • Instead of using break and a boolean sudokuStatus in your checkArrayStatus method, use a return statement

      while (i < 9) {
          if (rSumArray[i] != 45 && cSumArray[i] != 45 && rSumArray[i] != 45) {   
              return false;
          }
          i++;
      }
      return true;
    
  • Since the above loop is just doing a fixed-length iteration, replace while (i < 9) with

      for (int i = 0; i < 9; i++)
    
  • 9 is a "magic number" in your code. Let's say you wanted to change the Sudoku grid size (there are 4x4 Sudokus as well, in fact, almost any size is possible). If you wanted to change the size, you'd have to replace the value in many different places. Instead use a constant.

      public static final int GRID_SIZE = 9;
    

    Now, instead of writing 9 you can use GRID_SIZE

#And one major thing:

Just because some numbers sum up to 45 doesn't mean that it's valid in a Sudoku group!

Consider these numbers: 1, 1, 1, 1, 5, 9, 9, 9, 9. Do they some up to 45? Yes. Would it be a valid group/row/column in a Sudoku? NO! This is why @Vogel612's solution is a whole lot better.

Simon Forsberg
  • 59.7k
  • 9
  • 160
  • 312