Sudoku verifier program
The methods verifyRow, verifyCol, verifyGrid, and verifySudoku are all only accessed inside this class. Therefore, there is no point in making them public right?

If there do happen to be other classes, just they aren't shown here, you could probably leave verifySudoku as public because it makes sense for another class to possible access those.



I think Sudoku should be it's own, immutable, separate class. It should probably hold the 2D int array that is the sudoku board.

Now thinking about, the should be the class with the method verifySudoku (I'd call it isValid) because the method is to validate a sudoku board and the Sudoku class is holding a board to being with.

Here is what I came up with for the class:

public class Sudoku {
    private final int[][] board;
    private final int rows;
    private final int columns;

    public Sudoku(int[][] board, int rows, int columns) {
        this.board = board;
        this.rows = rows;
        this.columns = columns;
    }

    public boolean isValid(...) {
        [code]
    }

    private boolean verifyGrid(...) {
        [code]
    }

    private boolean verifyRow(...) {
        [code]
    }

    private boolean verifyCol(...) {
        [code]
    }
}




public boolean verifyRow(int arr[][], int num, int i, int j, int col) {


The argument names i and j are not descriptive whatsoever.



int k;
for (k = 0; k &lt; col; k++) {


You do not need to declare the iterator variable outside of the loop. This can and should be turned in to:

for (int k = 0; k &lt; col; k++) {




I think you have a very smart algorithm for verifying if the board.

Here is the way I thought of:


Create an java.util.ArrayList of the numbers 1-9.
In each verify method, copy this ArrayList.
Iterate through the row/column/grid's squares
If the number is in the array list, go to 6
If not, return false
Take the number out of the array list
If the array list is empty, return true
Go to 3


(I believe) This works because, by removing the numbers from the array list, you are making sure that that number is not repeated again in that row, which would make a row invalid if it contained 2+ of the same number.

Here is my implementation in Java:

private boolean verifyRow(int row) {
    List&lt;Integer&gt; numbers = new ArrayList&lt;Integer&gt;(this.allNumbers);

    for(int i = 0; i &lt; this.rows; i++) {
        if(numbers.contains(i)) {
            numbers.remove(new Integer(i)); // using java.util.ArrayList.remove(Object o) so I turned int i to an Integer
            if(numbers.isEmpty()) {
                return true;
            }
        } else {
            return false;
        }
    }
}


This used my Sudoku class idea.
allNumbers is the list of numbers 1-9 to copy.

I am not sure which version is faster.