title: Comparing values in an array in Java?
body: <p>I have a 2D array, which represents a Sudoku game.</p>
  
  <p>I'm trying to check the game for errors as with a typical Sudoku game:</p>
  
  <p>No number (1-9) is repeated within a row, column or 3x3 square.
  No empty cells.</p>
  
  <p>I'm very new to Java, so I had a limited knowledge to approach this with.  I was going to try a long if, else statement comparing all the cells.  That didn't work, because -1 was repeated. (-1 represents an empty square).  I tried to get around this, but realized that this if statement was too messy and there had to be a better way.</p>
  
  <p>I now think the best way to do it would be with a nested for loop to go through each row, column, and 3x3 square.  Checking for empty cells on the other hand, I think I've figured out. (nested for statement checking for -1 within the 2D array).</p>
  
  <p>I was also thinking of just adding up all the numbers in a row, col, or 3x3 square, and if it doesn't equal 45 then have the game remain incomplete?</p>
  
  <p>As far as checking repeat values, I'm not sure how to implement the nested for.</p>
  
  <p>EDIT: Let me clarify a bit, I don't really want to check for repeat values per say, I just want the game to remain incomplete if there is a repeat value. (e.g. Allow repeat values, just doesn't win you the game as with a real Sudoku puzzle).  I feel like the adding to 45 method would work best.</p>