Hi all - this is the code:

package sodukupackage;

import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;

public class ReadSudokuValuesIntoArray {

    public static void main(String[] args){
        int[][] sudoku = new int[9][9]; 
        Scanner sc = null; 

        try{
            int i = 0, j = 0, count = 1;

            sc = new Scanner(new File("validsudoku.txt"));
            while (sc.hasNextInt()){
                if((count % 9) == 0){
                    sudoku[i][j] = sc.nextInt();
                    count++;
                    i++;
                    j = 0;
                } else {
                    sudoku[i][j++] = sc.nextInt();
                    count++;
                }
            }
        }
        catch (FileNotFoundException fnfe){
            System.out.println("File not found.");
            System.exit(1);

        }
        finally {
            sc.close();
        }

        printArray(sudoku);
        rowsAreValid(sudoku);
        columnsAreValid(sudoku);
        regionsAreValid(sudoku);

    }

    public static void printArray(int[][] array){
        for(int i = 0; i < array.length; i++){
            for (int j = 0; j < array[i].length; j++){
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }

    public static boolean rowsAreValid(int[][] array){
        for (int i = 0; i < array.length; i++){
            for (int j = 0; j < array[i].length; j++){
                for (int column = 0; column < array.length; column++){
                    if (column != j && array[i][column] == array[i][j]){
                        return false;
                    }

                }

            }
        }
        return true;
    }

    public static boolean columnsAreValid(int[][] array){
        for (int i = 0; i < array.length; i++){
            for (int j = 0; j < array[i].length; j++){
                for(int row = 0; row < array.length; row++){
                    if (row != i && array[row][j] == array[i][j]){
                        return false;
                    }
                }
            }
        }
        return true;
    }

    public static boolean regionsAreValid(int[][] array){
        for (int i = 0; i < array.length; i++){
            for (int j = 0; j < array[i].length; j++){
                for (int row = (i/3) * 3; row < ( i / 3) * 3 + 3; row++){
                    for(int column = (j / 3) * 3; column < (j / 3) * 3 + 3; column++){
                        if (row != i && column != j && array[row][column] == array[i][j]){
                            return false;
                        }   
                    }
                }
            }
        }
    return true;
    }
}

My rowsAreValid and columns are valid methods work perfectly, but for some reason I can't quite figure out why my regionsareValid method won't work. I've tried changing numbers in the Sudoku puzzle to make it invalid, but the reigion checker always returns true even if it's false.

We read in a file that contains this:
5 9 3 1 7 8 6 4 2
1 8 2 6 3 4 9 7 5
6 7 4 9 2 5 8 1 3
3 2 1 4 5 9 7 6 8
8 4 5 3 6 7 2 9 1
9 6 7 8 1 2 5 3 4
7 1 6 2 8 3 4 5 9
2 5 9 7 4 1 3 8 6
4 3 8 5 9 6 1 2 7

Recommended Answers

All 19 Replies

why my regionsareValid method won't work.

Try debugging the code. One technique is to add println statements to print out the values of variables as there values are changed and used.
Where in the faulty method does the test fail to find the invalid data? Add some printlns there to display the values the program sees so you can understand why the code is doing what it is doing.
At line 86 print out the values of i,j,row and col and the data at those indexes so you see what the code sees and to make sure no values are skipped.

Are you sure your design/algorithm is correct for the method? Can you explain how the code is supposed to detect if a region is valid?

If the data shown in your post is what it read in, the region checker should return true because it is valid (there is no duplicated number in the 3x3 sub array in the example)...

I apologize, the data is what we read in for the tetsing of the code, but upon adding duplicate numbers for error testing, it still returns true regardless of how much I change the puzzle.

Have you tried debugging the code to see why it does what it does?

Please provide the invalid input as well...

public static boolean regionsAreValid(int[][] array){

        for (int i = 0; i < array.length; i++){
            for (int j = 0; j < array[i].length; j++){

                for (int row = (i / 3) * 3 ; row < (array.length / 3)* 3 + 3 ; row++){
                    System.out.println(row);
                    for(int column = (j / 3) * 3; column < (array[i].length / 3) * 3 + 3; column++){
                        System.out.println(column);
                        if(row != i && column != j && array[row][column] == array[i][j]){
                            System.out.println("False");
                            return false;
                        }
                    }

                }
            }
        }
        System.out.println("Correct!");
        return true;
    }
}

I added the println statements to see the output and I am getting:
0
0
1
2
3
4
5
6
7
8
9
10
11
1
0
1
2
3
4
5
6
7
8
False

I am beyond confused. My row and column method checker worked perfectlly fine but I can not for the life of me figure this out...and that is using:

5 9 3 1 7 8 6 4 2
1 8 2 6 3 4 9 7 5
6 7 4 9 2 5 8 1 3
3 2 1 4 5 9 7 6 8
8 4 5 3 6 7 2 9 1
9 6 7 8 1 2 5 3 4
7 1 6 2 8 3 4 5 9
2 5 9 7 4 1 3 8 6
4 3 8 5 9 6 1 2 7

Which is a valid puzzle and should return true..

Add a println statement to print out the values of ALL 5 of the variables used in the if statement that controls the execution of the return false; statement:
row, i, column, j, array[row][column], array[i][j]

The print out you posted doesn't have labels for any of the numbers it printed? Which are the values of row and which are column? You need to add ID Strings. For example:
System.out.println("row=" + row);

From your output, it is impossible to display anything above 9...

You could do it as...

public static boolean regionsAreValid(int[][] array) {
  for (int i = 0; i < array.length; i++){
    for (int j = 0; j < array[i].length; j++){
      for (int row = (i / 3) * 3 ; row < (array.length / 3)* 3 + 3 ; row++){
        System.out.println("Checking Row: "+row);  // update the print out
        for(int column = (j / 3) * 3; column < (array[i].length / 3) * 3 + 3; column++){
          System.out.println("        Col: "+column);  // update the print out
          if(row != i && column != j && array[row][column] == array[i][j]){
            // if it comes in here, you want to see which row & column
            // it is checking against i & j
            // also what value they are
            System.out.println("Value at ("+i+","+j+") is "+array[i][j]);
            System.out.println("Value at ("+row+","+column+") is "+array[row][column]);
            return false;
          }
        }
      }
    }
  }
  System.out.println("Correct!");
  return true;
}

Edit:
I just look at the code again and found that (array.length / 3)* 3 + 3 is the culprit. What it means is that it will be equal to array.length + 3 and that will be wrong.

For the row part, it should be...

for (int row=(i/3)*3; row < (i/3)*3 + 3; row++) {

and the column should be

for (int column=(j/3)*3; column < (j/3)*3 + 3; column++) {

I added the additional printlns here...

public static boolean regionsAreValid(int[][] array){

        for (int i = 0; i < array.length; i++){
            for (int j = 0; j < array[i].length; j++){

                for (int row = (i / 3) * 3 ; row < (array.length / 3)* 3 + 3 ; row++){
                    for(int column = (j / 3) * 3; column < (array[i].length / 3) * 3 + 3; column++){
                        System.out.println("column=" + column);
                        System.out.println("j=" + j);
                        System.out.println("row=" + row);
                        System.out.println("i=" + i);
                        if(row != i && column != j && array[row][column] == array[i][j]){
                            System.out.println("array[i][j]=" + array[i][j]);
                            System.out.println("array[row][column]=" + array[row][column]);
                            System.out.println("False");
                            return false;
                        }
                    }

                }
            }
        }
        System.out.println("Correct!");
        return true;
    }
}

The output is as follows:

column=0
j=0
row=0
i=0
column=1
j=0
row=0
i=0
column=2
j=0
row=0
i=0
column=3
j=0
row=0
i=0
column=4
j=0
row=0
i=0
column=5
j=0
row=0
i=0
column=6
j=0
row=0
i=0
column=7
j=0
row=0
i=0
column=8
j=0
row=0
i=0
column=9
j=0
row=0
i=0
column=10
j=0
row=0
i=0
column=11
j=0
row=0
i=0
column=0
j=0
row=1
i=0
column=1
j=0
row=1
i=0
column=2
j=0
row=1
i=0
column=3
j=0
row=1
i=0
column=4
j=0
row=1
i=0
column=5
j=0
row=1
i=0
column=6
j=0
row=1
i=0
column=7
j=0
row=1
i=0
column=8
j=0
row=1
i=0
array[i][j]=5
array[row][column]=5
False

Please read my edit (previous post)

column=8
j=0
row=1
i=0
array[i][j]=5
array[row][column]=5
False

Do the two array entries [0,0] and [1,8] being equal(value=5) make sense?

That did fix some of the issues, however, now I am having a problem with it not returning false if the sudoku puzzle is false.

For the input:

5 9 3 1 7 8 6 4 2
1 8 2 6 3 4 9 7 5
6 7 4 9 2 5 8 1 3
3 2 1 4 5 9 7 6 8
8 4 5 3 6 7 2 9 1
9 6 7 8 1 2 5 3 4
7 1 6 2 8 3 4 5 9
2 5 9 7 4 1 3 8 6
4 3 8 5 9 6 1 2 7

...

If I change the first number and make the puzzle:

9 9 3 1 7 8 6 4 2
1 8 2 6 3 4 9 7 5
6 7 4 9 2 5 8 1 3
3 2 1 4 5 9 7 6 8
8 4 5 3 6 7 2 9 1
9 6 7 8 1 2 5 3 4
7 1 6 2 8 3 4 5 9
2 5 9 7 4 1 3 8 6
4 3 8 5 9 6 1 2 7

It is still returning correct even though the puzzle is incorrect.

Below is my test on checking row/column/region using your method (with updated from my post). It is correct. It looks like someone else posted the same question before. Have you tried to print out what values you are storing in your puzzle array?

I need to see how you implement other methods before you call this method?

>java ReadSudokuValuesIntoArray 
9 9 3 1 7 8 6 4 2 
1 4 2 6 3 4 9 7 5 
6 7 4 9 2 5 8 1 3 
3 2 1 4 5 9 7 6 8 
8 8 5 3 6 7 2 9 1 
9 6 7 8 1 2 5 3 4 
7 1 6 2 8 3 4 5 9 
2 5 9 7 4 1 3 8 6 
4 3 8 5 9 6 1 2 7 
Reg:false

returning correct even though the puzzle is incorrect.

Continue debugging. The printed out values should show you all the comparisons that are being made. Examine them closely to make sure all the comparisons are being made that will find the error.

Your print outs take too many lines. Print some of the values of the same line. For example :
System.out.println("array[i][j]=" + array[i][j] + ", array[row][column]=" + array[row][column]);

Instead of having 4 printlns in a row, merge all the items to one line.

package sodukupackage;

import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;

public class ReadSudokuValuesIntoArray {

    public static void main(String[] args){
        int[][] sudoku = new int[9][9]; 
        Scanner sc = null; 

        try{
            int i = 0, j = 0, count = 1;

            sc = new Scanner(new File("validsudoku.txt"));
            while (sc.hasNextInt()){
                if((count % 9) == 0){
                    sudoku[i][j] = sc.nextInt();
                    count++;
                    i++;
                    j = 0;
                } else {
                    sudoku[i][j++] = sc.nextInt();
                    count++;
                }
            }
        }
        catch (FileNotFoundException fnfe){
            System.out.println("File not found.");
            System.exit(1);

        }
        finally {
            sc.close();
        }

        printArray(sudoku);
        rowsAreValid(sudoku);
        columnsAreValid(sudoku);
        regionsAreValid(sudoku);

    }

    public static void printArray(int[][] array){
        for(int i = 0; i < array.length; i++){
            for (int j = 0; j < array[i].length; j++){
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }

    public static boolean rowsAreValid(int[][] array){
        for (int i = 0; i < array.length; i++){
            for (int j = 0; j < array[i].length; j++){
                for (int column = 0; column < array.length; column++){
                    if (column != j && array[i][column] == array[i][j]){
                        return false;
                    }

                }

            }
        }
        return true;
    }

    public static boolean columnsAreValid(int[][] array){
        for (int i = 0; i < array.length; i++){
            for (int j = 0; j < array[i].length; j++){
                for(int row = 0; row < array.length; row++){
                    if (row != i && array[row][j] == array[i][j]){
                        return false;
                    }
                }
            }
        }
        return true;
    }

    public static boolean regionsAreValid(int[][] array){

        for (int i = 0; i < array.length; i++){
            for (int j = 0; j < array[i].length; j++){

                for (int row = (i / 3) * 3 ; row < (i / 3)* 3 + 3 ; row++){
                    for(int column = (j / 3) * 3; column < (j / 3) * 3 + 3; column++){
                        System.out.println("column=" + column);
                        System.out.println("j=" + j);
                        System.out.println("row=" + row);
                        System.out.println("i=" + i);
                        if(row != i && column != j && array[row][column] == array[i][j]){
                            System.out.println("array[i][j]=" + array[i][j]);
                            System.out.println("array[row][column]=" + array[row][column]);
                            System.out.println("False");
                            return false;
                        }
                    }
                }
            }
        }
        System.out.println("Correct!");
        return true;
    }
}

Here's the entirety of the code so you can see how I implement the methods.

Change the println calls so that they only print two lines, instead of 6 lines.
See my last post.

Upon merging println statements, the output is correct, even with a wrong Sudoku solution:

column=0, j=0,row=0,i=0
column=1, j=0,row=0,i=0
column=2, j=0,row=0,i=0
column=0, j=0,row=1,i=0
column=1, j=0,row=1,i=0
column=2, j=0,row=1,i=0
column=0, j=0,row=2,i=0
column=1, j=0,row=2,i=0
column=2, j=0,row=2,i=0
column=0, j=1,row=0,i=0
column=1, j=1,row=0,i=0
column=2, j=1,row=0,i=0
column=0, j=1,row=1,i=0
column=1, j=1,row=1,i=0
column=2, j=1,row=1,i=0
column=0, j=1,row=2,i=0
column=1, j=1,row=2,i=0
column=2, j=1,row=2,i=0
column=0, j=2,row=0,i=0
column=1, j=2,row=0,i=0
column=2, j=2,row=0,i=0
column=0, j=2,row=1,i=0
column=1, j=2,row=1,i=0
column=2, j=2,row=1,i=0
column=0, j=2,row=2,i=0
column=1, j=2,row=2,i=0
column=2, j=2,row=2,i=0
column=3, j=3,row=0,i=0
column=4, j=3,row=0,i=0
column=5, j=3,row=0,i=0
column=3, j=3,row=1,i=0
column=4, j=3,row=1,i=0
column=5, j=3,row=1,i=0
column=3, j=3,row=2,i=0
column=4, j=3,row=2,i=0
column=5, j=3,row=2,i=0
column=3, j=4,row=0,i=0
column=4, j=4,row=0,i=0
column=5, j=4,row=0,i=0
column=3, j=4,row=1,i=0
column=4, j=4,row=1,i=0
column=5, j=4,row=1,i=0
column=3, j=4,row=2,i=0
column=4, j=4,row=2,i=0
column=5, j=4,row=2,i=0
column=3, j=5,row=0,i=0
column=4, j=5,row=0,i=0
column=5, j=5,row=0,i=0
column=3, j=5,row=1,i=0
column=4, j=5,row=1,i=0
column=5, j=5,row=1,i=0
column=3, j=5,row=2,i=0
column=4, j=5,row=2,i=0
column=5, j=5,row=2,i=0
column=6, j=6,row=0,i=0
column=7, j=6,row=0,i=0
column=8, j=6,row=0,i=0
column=6, j=6,row=1,i=0
column=7, j=6,row=1,i=0
column=8, j=6,row=1,i=0
column=6, j=6,row=2,i=0
column=7, j=6,row=2,i=0
column=8, j=6,row=2,i=0
column=6, j=7,row=0,i=0
column=7, j=7,row=0,i=0
column=8, j=7,row=0,i=0
column=6, j=7,row=1,i=0
column=7, j=7,row=1,i=0
column=8, j=7,row=1,i=0
column=6, j=7,row=2,i=0
column=7, j=7,row=2,i=0
column=8, j=7,row=2,i=0
column=6, j=8,row=0,i=0
column=7, j=8,row=0,i=0
column=8, j=8,row=0,i=0
column=6, j=8,row=1,i=0
column=7, j=8,row=1,i=0
column=8, j=8,row=1,i=0
column=6, j=8,row=2,i=0
column=7, j=8,row=2,i=0
column=8, j=8,row=2,i=0
column=0, j=0,row=0,i=1
column=1, j=0,row=0,i=1
column=2, j=0,row=0,i=1
column=0, j=0,row=1,i=1
column=1, j=0,row=1,i=1
column=2, j=0,row=1,i=1
column=0, j=0,row=2,i=1
column=1, j=0,row=2,i=1
column=2, j=0,row=2,i=1
column=0, j=1,row=0,i=1
column=1, j=1,row=0,i=1
column=2, j=1,row=0,i=1
column=0, j=1,row=1,i=1
column=1, j=1,row=1,i=1
column=2, j=1,row=1,i=1
column=0, j=1,row=2,i=1
column=1, j=1,row=2,i=1
column=2, j=1,row=2,i=1
column=0, j=2,row=0,i=1
column=1, j=2,row=0,i=1
column=2, j=2,row=0,i=1
column=0, j=2,row=1,i=1
column=1, j=2,row=1,i=1
column=2, j=2,row=1,i=1
column=0, j=2,row=2,i=1
column=1, j=2,row=2,i=1
column=2, j=2,row=2,i=1
column=3, j=3,row=0,i=1
column=4, j=3,row=0,i=1
column=5, j=3,row=0,i=1
column=3, j=3,row=1,i=1
column=4, j=3,row=1,i=1
column=5, j=3,row=1,i=1
column=3, j=3,row=2,i=1
column=4, j=3,row=2,i=1
column=5, j=3,row=2,i=1
column=3, j=4,row=0,i=1
column=4, j=4,row=0,i=1
column=5, j=4,row=0,i=1
column=3, j=4,row=1,i=1
column=4, j=4,row=1,i=1
column=5, j=4,row=1,i=1
column=3, j=4,row=2,i=1
column=4, j=4,row=2,i=1
column=5, j=4,row=2,i=1
column=3, j=5,row=0,i=1
column=4, j=5,row=0,i=1
column=5, j=5,row=0,i=1
column=3, j=5,row=1,i=1
column=4, j=5,row=1,i=1
column=5, j=5,row=1,i=1
column=3, j=5,row=2,i=1
column=4, j=5,row=2,i=1
column=5, j=5,row=2,i=1
column=6, j=6,row=0,i=1
column=7, j=6,row=0,i=1
column=8, j=6,row=0,i=1
column=6, j=6,row=1,i=1
column=7, j=6,row=1,i=1
column=8, j=6,row=1,i=1
column=6, j=6,row=2,i=1
column=7, j=6,row=2,i=1
column=8, j=6,row=2,i=1
column=6, j=7,row=0,i=1
column=7, j=7,row=0,i=1
column=8, j=7,row=0,i=1
column=6, j=7,row=1,i=1
column=7, j=7,row=1,i=1
column=8, j=7,row=1,i=1
column=6, j=7,row=2,i=1
column=7, j=7,row=2,i=1
column=8, j=7,row=2,i=1
column=6, j=8,row=0,i=1
column=7, j=8,row=0,i=1
column=8, j=8,row=0,i=1
column=6, j=8,row=1,i=1
column=7, j=8,row=1,i=1
column=8, j=8,row=1,i=1
column=6, j=8,row=2,i=1
column=7, j=8,row=2,i=1
column=8, j=8,row=2,i=1
column=0, j=0,row=0,i=2
column=1, j=0,row=0,i=2
column=2, j=0,row=0,i=2
column=0, j=0,row=1,i=2
column=1, j=0,row=1,i=2
column=2, j=0,row=1,i=2
column=0, j=0,row=2,i=2
column=1, j=0,row=2,i=2
column=2, j=0,row=2,i=2
column=0, j=1,row=0,i=2
column=1, j=1,row=0,i=2
column=2, j=1,row=0,i=2
column=0, j=1,row=1,i=2
column=1, j=1,row=1,i=2
column=2, j=1,row=1,i=2
column=0, j=1,row=2,i=2
column=1, j=1,row=2,i=2
column=2, j=1,row=2,i=2
column=0, j=2,row=0,i=2
column=1, j=2,row=0,i=2
column=2, j=2,row=0,i=2
column=0, j=2,row=1,i=2
column=1, j=2,row=1,i=2
column=2, j=2,row=1,i=2
column=0, j=2,row=2,i=2
column=1, j=2,row=2,i=2
column=2, j=2,row=2,i=2
column=3, j=3,row=0,i=2
column=4, j=3,row=0,i=2
column=5, j=3,row=0,i=2
column=3, j=3,row=1,i=2
column=4, j=3,row=1,i=2
column=5, j=3,row=1,i=2
column=3, j=3,row=2,i=2
column=4, j=3,row=2,i=2
column=5, j=3,row=2,i=2
column=3, j=4,row=0,i=2
column=4, j=4,row=0,i=2
column=5, j=4,row=0,i=2
column=3, j=4,row=1,i=2
column=4, j=4,row=1,i=2
column=5, j=4,row=1,i=2
column=3, j=4,row=2,i=2
column=4, j=4,row=2,i=2
column=5, j=4,row=2,i=2
column=3, j=5,row=0,i=2
column=4, j=5,row=0,i=2
column=5, j=5,row=0,i=2
column=3, j=5,row=1,i=2
column=4, j=5,row=1,i=2
column=5, j=5,row=1,i=2
column=3, j=5,row=2,i=2
column=4, j=5,row=2,i=2
column=5, j=5,row=2,i=2
column=6, j=6,row=0,i=2
column=7, j=6,row=0,i=2
column=8, j=6,row=0,i=2
column=6, j=6,row=1,i=2
column=7, j=6,row=1,i=2
column=8, j=6,row=1,i=2
column=6, j=6,row=2,i=2
column=7, j=6,row=2,i=2
column=8, j=6,row=2,i=2
column=6, j=7,row=0,i=2
column=7, j=7,row=0,i=2
column=8, j=7,row=0,i=2
column=6, j=7,row=1,i=2
column=7, j=7,row=1,i=2
column=8, j=7,row=1,i=2
column=6, j=7,row=2,i=2
column=7, j=7,row=2,i=2
column=8, j=7,row=2,i=2
column=6, j=8,row=0,i=2
column=7, j=8,row=0,i=2
column=8, j=8,row=0,i=2
column=6, j=8,row=1,i=2
column=7, j=8,row=1,i=2
column=8, j=8,row=1,i=2
column=6, j=8,row=2,i=2
column=7, j=8,row=2,i=2
column=8, j=8,row=2,i=2
column=0, j=0,row=3,i=3
column=1, j=0,row=3,i=3
column=2, j=0,row=3,i=3
column=0, j=0,row=4,i=3
column=1, j=0,row=4,i=3
column=2, j=0,row=4,i=3
column=0, j=0,row=5,i=3
column=1, j=0,row=5,i=3
column=2, j=0,row=5,i=3
column=0, j=1,row=3,i=3
column=1, j=1,row=3,i=3
column=2, j=1,row=3,i=3
column=0, j=1,row=4,i=3
column=1, j=1,row=4,i=3
column=2, j=1,row=4,i=3
column=0, j=1,row=5,i=3
column=1, j=1,row=5,i=3
column=2, j=1,row=5,i=3
column=0, j=2,row=3,i=3
column=1, j=2,row=3,i=3
column=2, j=2,row=3,i=3
column=0, j=2,row=4,i=3
column=1, j=2,row=4,i=3
column=2, j=2,row=4,i=3
column=0, j=2,row=5,i=3
column=1, j=2,row=5,i=3
column=2, j=2,row=5,i=3
column=3, j=3,row=3,i=3
column=4, j=3,row=3,i=3
column=5, j=3,row=3,i=3
column=3, j=3,row=4,i=3
column=4, j=3,row=4,i=3
column=5, j=3,row=4,i=3
column=3, j=3,row=5,i=3
column=4, j=3,row=5,i=3
column=5, j=3,row=5,i=3
column=3, j=4,row=3,i=3
column=4, j=4,row=3,i=3
column=5, j=4,row=3,i=3
column=3, j=4,row=4,i=3
column=4, j=4,row=4,i=3
column=5, j=4,row=4,i=3
column=3, j=4,row=5,i=3
column=4, j=4,row=5,i=3
column=5, j=4,row=5,i=3
column=3, j=5,row=3,i=3
column=4, j=5,row=3,i=3
column=5, j=5,row=3,i=3
column=3, j=5,row=4,i=3
column=4, j=5,row=4,i=3
column=5, j=5,row=4,i=3
column=3, j=5,row=5,i=3
column=4, j=5,row=5,i=3
column=5, j=5,row=5,i=3
column=6, j=6,row=3,i=3
column=7, j=6,row=3,i=3
column=8, j=6,row=3,i=3
column=6, j=6,row=4,i=3
column=7, j=6,row=4,i=3
column=8, j=6,row=4,i=3
column=6, j=6,row=5,i=3
column=7, j=6,row=5,i=3
column=8, j=6,row=5,i=3
column=6, j=7,row=3,i=3
column=7, j=7,row=3,i=3
column=8, j=7,row=3,i=3
column=6, j=7,row=4,i=3
column=7, j=7,row=4,i=3
column=8, j=7,row=4,i=3
column=6, j=7,row=5,i=3
column=7, j=7,row=5,i=3
column=8, j=7,row=5,i=3
column=6, j=8,row=3,i=3
column=7, j=8,row=3,i=3
column=8, j=8,row=3,i=3
column=6, j=8,row=4,i=3
column=7, j=8,row=4,i=3
column=8, j=8,row=4,i=3
column=6, j=8,row=5,i=3
column=7, j=8,row=5,i=3
column=8, j=8,row=5,i=3
column=0, j=0,row=3,i=4
column=1, j=0,row=3,i=4
column=2, j=0,row=3,i=4
column=0, j=0,row=4,i=4
column=1, j=0,row=4,i=4
column=2, j=0,row=4,i=4
column=0, j=0,row=5,i=4
column=1, j=0,row=5,i=4
column=2, j=0,row=5,i=4
column=0, j=1,row=3,i=4
column=1, j=1,row=3,i=4
column=2, j=1,row=3,i=4
column=0, j=1,row=4,i=4
column=1, j=1,row=4,i=4
column=2, j=1,row=4,i=4
column=0, j=1,row=5,i=4
column=1, j=1,row=5,i=4
column=2, j=1,row=5,i=4
column=0, j=2,row=3,i=4
column=1, j=2,row=3,i=4
column=2, j=2,row=3,i=4
column=0, j=2,row=4,i=4
column=1, j=2,row=4,i=4
column=2, j=2,row=4,i=4
column=0, j=2,row=5,i=4
column=1, j=2,row=5,i=4
column=2, j=2,row=5,i=4
column=3, j=3,row=3,i=4
column=4, j=3,row=3,i=4
column=5, j=3,row=3,i=4
column=3, j=3,row=4,i=4
column=4, j=3,row=4,i=4
column=5, j=3,row=4,i=4
column=3, j=3,row=5,i=4
column=4, j=3,row=5,i=4
column=5, j=3,row=5,i=4
column=3, j=4,row=3,i=4
column=4, j=4,row=3,i=4
column=5, j=4,row=3,i=4
column=3, j=4,row=4,i=4
column=4, j=4,row=4,i=4
column=5, j=4,row=4,i=4
column=3, j=4,row=5,i=4
column=4, j=4,row=5,i=4
column=5, j=4,row=5,i=4
column=3, j=5,row=3,i=4
column=4, j=5,row=3,i=4
column=5, j=5,row=3,i=4
column=3, j=5,row=4,i=4
column=4, j=5,row=4,i=4
column=5, j=5,row=4,i=4
column=3, j=5,row=5,i=4
column=4, j=5,row=5,i=4
column=5, j=5,row=5,i=4
column=6, j=6,row=3,i=4
column=7, j=6,row=3,i=4
column=8, j=6,row=3,i=4
column=6, j=6,row=4,i=4
column=7, j=6,row=4,i=4
column=8, j=6,row=4,i=4
column=6, j=6,row=5,i=4
column=7, j=6,row=5,i=4
column=8, j=6,row=5,i=4
column=6, j=7,row=3,i=4
column=7, j=7,row=3,i=4
column=8, j=7,row=3,i=4
column=6, j=7,row=4,i=4
column=7, j=7,row=4,i=4
column=8, j=7,row=4,i=4
column=6, j=7,row=5,i=4
column=7, j=7,row=5,i=4
column=8, j=7,row=5,i=4
column=6, j=8,row=3,i=4
column=7, j=8,row=3,i=4
column=8, j=8,row=3,i=4
column=6, j=8,row=4,i=4
column=7, j=8,row=4,i=4
column=8, j=8,row=4,i=4
column=6, j=8,row=5,i=4
column=7, j=8,row=5,i=4
column=8, j=8,row=5,i=4
column=0, j=0,row=3,i=5
column=1, j=0,row=3,i=5
column=2, j=0,row=3,i=5
column=0, j=0,row=4,i=5
column=1, j=0,row=4,i=5
column=2, j=0,row=4,i=5
column=0, j=0,row=5,i=5
column=1, j=0,row=5,i=5
column=2, j=0,row=5,i=5
column=0, j=1,row=3,i=5
column=1, j=1,row=3,i=5
column=2, j=1,row=3,i=5
column=0, j=1,row=4,i=5
column=1, j=1,row=4,i=5
column=2, j=1,row=4,i=5
column=0, j=1,row=5,i=5
column=1, j=1,row=5,i=5
column=2, j=1,row=5,i=5
column=0, j=2,row=3,i=5
column=1, j=2,row=3,i=5
column=2, j=2,row=3,i=5
column=0, j=2,row=4,i=5
column=1, j=2,row=4,i=5
column=2, j=2,row=4,i=5
column=0, j=2,row=5,i=5
column=1, j=2,row=5,i=5
column=2, j=2,row=5,i=5
column=3, j=3,row=3,i=5
column=4, j=3,row=3,i=5
column=5, j=3,row=3,i=5
column=3, j=3,row=4,i=5
column=4, j=3,row=4,i=5
column=5, j=3,row=4,i=5
column=3, j=3,row=5,i=5
column=4, j=3,row=5,i=5
column=5, j=3,row=5,i=5
column=3, j=4,row=3,i=5
column=4, j=4,row=3,i=5
column=5, j=4,row=3,i=5
column=3, j=4,row=4,i=5
column=4, j=4,row=4,i=5
column=5, j=4,row=4,i=5
column=3, j=4,row=5,i=5
column=4, j=4,row=5,i=5
column=5, j=4,row=5,i=5
column=3, j=5,row=3,i=5
column=4, j=5,row=3,i=5
column=5, j=5,row=3,i=5
column=3, j=5,row=4,i=5
column=4, j=5,row=4,i=5
column=5, j=5,row=4,i=5
column=3, j=5,row=5,i=5
column=4, j=5,row=5,i=5
column=5, j=5,row=5,i=5
column=6, j=6,row=3,i=5
column=7, j=6,row=3,i=5
column=8, j=6,row=3,i=5
column=6, j=6,row=4,i=5
column=7, j=6,row=4,i=5
column=8, j=6,row=4,i=5
column=6, j=6,row=5,i=5
column=7, j=6,row=5,i=5
column=8, j=6,row=5,i=5
column=6, j=7,row=3,i=5
column=7, j=7,row=3,i=5
column=8, j=7,row=3,i=5
column=6, j=7,row=4,i=5
column=7, j=7,row=4,i=5
column=8, j=7,row=4,i=5
column=6, j=7,row=5,i=5
column=7, j=7,row=5,i=5
column=8, j=7,row=5,i=5
column=6, j=8,row=3,i=5
column=7, j=8,row=3,i=5
column=8, j=8,row=3,i=5
column=6, j=8,row=4,i=5
column=7, j=8,row=4,i=5
column=8, j=8,row=4,i=5
column=6, j=8,row=5,i=5
column=7, j=8,row=5,i=5
column=8, j=8,row=5,i=5
column=0, j=0,row=6,i=6
column=1, j=0,row=6,i=6
column=2, j=0,row=6,i=6
column=0, j=0,row=7,i=6
column=1, j=0,row=7,i=6
column=2, j=0,row=7,i=6
column=0, j=0,row=8,i=6
column=1, j=0,row=8,i=6
column=2, j=0,row=8,i=6
column=0, j=1,row=6,i=6
column=1, j=1,row=6,i=6
column=2, j=1,row=6,i=6
column=0, j=1,row=7,i=6
column=1, j=1,row=7,i=6
column=2, j=1,row=7,i=6
column=0, j=1,row=8,i=6
column=1, j=1,row=8,i=6
column=2, j=1,row=8,i=6
column=0, j=2,row=6,i=6
column=1, j=2,row=6,i=6
column=2, j=2,row=6,i=6
column=0, j=2,row=7,i=6
column=1, j=2,row=7,i=6
column=2, j=2,row=7,i=6
column=0, j=2,row=8,i=6
column=1, j=2,row=8,i=6
column=2, j=2,row=8,i=6
column=3, j=3,row=6,i=6
column=4, j=3,row=6,i=6
column=5, j=3,row=6,i=6
column=3, j=3,row=7,i=6
column=4, j=3,row=7,i=6
column=5, j=3,row=7,i=6
column=3, j=3,row=8,i=6
column=4, j=3,row=8,i=6
column=5, j=3,row=8,i=6
column=3, j=4,row=6,i=6
column=4, j=4,row=6,i=6
column=5, j=4,row=6,i=6
column=3, j=4,row=7,i=6
column=4, j=4,row=7,i=6
column=5, j=4,row=7,i=6
column=3, j=4,row=8,i=6
column=4, j=4,row=8,i=6
column=5, j=4,row=8,i=6
column=3, j=5,row=6,i=6
column=4, j=5,row=6,i=6
column=5, j=5,row=6,i=6
column=3, j=5,row=7,i=6
column=4, j=5,row=7,i=6
column=5, j=5,row=7,i=6
column=3, j=5,row=8,i=6
column=4, j=5,row=8,i=6
column=5, j=5,row=8,i=6
column=6, j=6,row=6,i=6
column=7, j=6,row=6,i=6
column=8, j=6,row=6,i=6
column=6, j=6,row=7,i=6
column=7, j=6,row=7,i=6
column=8, j=6,row=7,i=6
column=6, j=6,row=8,i=6
column=7, j=6,row=8,i=6
column=8, j=6,row=8,i=6
column=6, j=7,row=6,i=6
column=7, j=7,row=6,i=6
column=8, j=7,row=6,i=6
column=6, j=7,row=7,i=6
column=7, j=7,row=7,i=6
column=8, j=7,row=7,i=6
column=6, j=7,row=8,i=6
column=7, j=7,row=8,i=6
column=8, j=7,row=8,i=6
column=6, j=8,row=6,i=6
column=7, j=8,row=6,i=6
column=8, j=8,row=6,i=6
column=6, j=8,row=7,i=6
column=7, j=8,row=7,i=6
column=8, j=8,row=7,i=6
column=6, j=8,row=8,i=6
column=7, j=8,row=8,i=6
column=8, j=8,row=8,i=6
column=0, j=0,row=6,i=7
column=1, j=0,row=6,i=7
column=2, j=0,row=6,i=7
column=0, j=0,row=7,i=7
column=1, j=0,row=7,i=7
column=2, j=0,row=7,i=7
column=0, j=0,row=8,i=7
column=1, j=0,row=8,i=7
column=2, j=0,row=8,i=7
column=0, j=1,row=6,i=7
column=1, j=1,row=6,i=7
column=2, j=1,row=6,i=7
column=0, j=1,row=7,i=7
column=1, j=1,row=7,i=7
column=2, j=1,row=7,i=7
column=0, j=1,row=8,i=7
column=1, j=1,row=8,i=7
column=2, j=1,row=8,i=7
column=0, j=2,row=6,i=7
column=1, j=2,row=6,i=7
column=2, j=2,row=6,i=7
column=0, j=2,row=7,i=7
column=1, j=2,row=7,i=7
column=2, j=2,row=7,i=7
column=0, j=2,row=8,i=7
column=1, j=2,row=8,i=7
column=2, j=2,row=8,i=7
column=3, j=3,row=6,i=7
column=4, j=3,row=6,i=7
column=5, j=3,row=6,i=7
column=3, j=3,row=7,i=7
column=4, j=3,row=7,i=7
column=5, j=3,row=7,i=7
column=3, j=3,row=8,i=7
column=4, j=3,row=8,i=7
column=5, j=3,row=8,i=7
column=3, j=4,row=6,i=7
column=4, j=4,row=6,i=7
column=5, j=4,row=6,i=7
column=3, j=4,row=7,i=7
column=4, j=4,row=7,i=7
column=5, j=4,row=7,i=7
column=3, j=4,row=8,i=7
column=4, j=4,row=8,i=7
column=5, j=4,row=8,i=7
column=3, j=5,row=6,i=7
column=4, j=5,row=6,i=7
column=5, j=5,row=6,i=7
column=3, j=5,row=7,i=7
column=4, j=5,row=7,i=7
column=5, j=5,row=7,i=7
column=3, j=5,row=8,i=7
column=4, j=5,row=8,i=7
column=5, j=5,row=8,i=7
column=6, j=6,row=6,i=7
column=7, j=6,row=6,i=7
column=8, j=6,row=6,i=7
column=6, j=6,row=7,i=7
column=7, j=6,row=7,i=7
column=8, j=6,row=7,i=7
column=6, j=6,row=8,i=7
column=7, j=6,row=8,i=7
column=8, j=6,row=8,i=7
column=6, j=7,row=6,i=7
column=7, j=7,row=6,i=7
column=8, j=7,row=6,i=7
column=6, j=7,row=7,i=7
column=7, j=7,row=7,i=7
column=8, j=7,row=7,i=7
column=6, j=7,row=8,i=7
column=7, j=7,row=8,i=7
column=8, j=7,row=8,i=7
column=6, j=8,row=6,i=7
column=7, j=8,row=6,i=7
column=8, j=8,row=6,i=7
column=6, j=8,row=7,i=7
column=7, j=8,row=7,i=7
column=8, j=8,row=7,i=7
column=6, j=8,row=8,i=7
column=7, j=8,row=8,i=7
column=8, j=8,row=8,i=7
column=0, j=0,row=6,i=8
column=1, j=0,row=6,i=8
column=2, j=0,row=6,i=8
column=0, j=0,row=7,i=8
column=1, j=0,row=7,i=8
column=2, j=0,row=7,i=8
column=0, j=0,row=8,i=8
column=1, j=0,row=8,i=8
column=2, j=0,row=8,i=8
column=0, j=1,row=6,i=8
column=1, j=1,row=6,i=8
column=2, j=1,row=6,i=8
column=0, j=1,row=7,i=8
column=1, j=1,row=7,i=8
column=2, j=1,row=7,i=8
column=0, j=1,row=8,i=8
column=1, j=1,row=8,i=8
column=2, j=1,row=8,i=8
column=0, j=2,row=6,i=8
column=1, j=2,row=6,i=8
column=2, j=2,row=6,i=8
column=0, j=2,row=7,i=8
column=1, j=2,row=7,i=8
column=2, j=2,row=7,i=8
column=0, j=2,row=8,i=8
column=1, j=2,row=8,i=8
column=2, j=2,row=8,i=8
column=3, j=3,row=6,i=8
column=4, j=3,row=6,i=8
column=5, j=3,row=6,i=8
column=3, j=3,row=7,i=8
column=4, j=3,row=7,i=8
column=5, j=3,row=7,i=8
column=3, j=3,row=8,i=8
column=4, j=3,row=8,i=8
column=5, j=3,row=8,i=8
column=3, j=4,row=6,i=8
column=4, j=4,row=6,i=8
column=5, j=4,row=6,i=8
column=3, j=4,row=7,i=8
column=4, j=4,row=7,i=8
column=5, j=4,row=7,i=8
column=3, j=4,row=8,i=8
column=4, j=4,row=8,i=8
column=5, j=4,row=8,i=8
column=3, j=5,row=6,i=8
column=4, j=5,row=6,i=8
column=5, j=5,row=6,i=8
column=3, j=5,row=7,i=8
column=4, j=5,row=7,i=8
column=5, j=5,row=7,i=8
column=3, j=5,row=8,i=8
column=4, j=5,row=8,i=8
column=5, j=5,row=8,i=8
column=6, j=6,row=6,i=8
column=7, j=6,row=6,i=8
column=8, j=6,row=6,i=8
column=6, j=6,row=7,i=8
column=7, j=6,row=7,i=8
column=8, j=6,row=7,i=8
column=6, j=6,row=8,i=8
column=7, j=6,row=8,i=8
column=8, j=6,row=8,i=8
column=6, j=7,row=6,i=8
column=7, j=7,row=6,i=8
column=8, j=7,row=6,i=8
column=6, j=7,row=7,i=8
column=7, j=7,row=7,i=8
column=8, j=7,row=7,i=8
column=6, j=7,row=8,i=8
column=7, j=7,row=8,i=8
column=8, j=7,row=8,i=8
column=6, j=8,row=6,i=8
column=7, j=8,row=6,i=8
column=8, j=8,row=6,i=8
column=6, j=8,row=7,i=8
column=7, j=8,row=7,i=8
column=8, j=8,row=7,i=8
column=6, j=8,row=8,i=8
column=7, j=8,row=8,i=8
column=8, j=8,row=8,i=8
Correct!

There is no need to post all that. The if test should fail very quickly because the error is in the first row. The if statement should find the error when comparing 0,0 and 0,1. Those are the two pairs of indexes you want to see the results for in the print out.

You also need to print out the values from the array that are being compared in the if statement.

To reduce the print out, add this line before the call to println() so it only prints out when looking at the first two rows and columns:

if(i < 2 && row < 2 && j < 2 && column < 2)  // only print first two row/cols

I tested your code and it worked correctly (return false with an incorrect sudoku value)??? You should check what goes in (look at the printArray result) and your result. What might have happened here is that you read in a correct puzzle but thought it was a modified one that is an incorrect...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.