比较某个块Sudoku Java中的整数

时间:2012-02-19 06:32:53

标签: java sudoku

所以我更新了我的代码,我仍然难以检查如何在已完成的数独板中检查3x3块以查看它是否没有任何重复数字。这是我更新的方法。

static boolean isBlock1Valid(int[][] sudokuBoard, int referenceRow, int referenceColumn)
{

    boolean[] seen = new boolean[9];

    for (int i = 0; i < 3; i++){

        for (int j = 0; j < 3; j++){

            if ( seen(sudokuBoard[referenceColumn+i][referenceRow+j])) return false;


    else ( seen(sudokuBoard[referenceColumn+i][referenceRow+j])) = true;
    }
    }
return true;
}//end of isBlock1Valid

这是调用方法我不知道要向方法发送哪些参数isBlock1Valid

    public static void Validate(final int[][] sudokuBoard)
{
    int width = sudokuBoard[0].length;
    int height = sudokuBoard.length;

    for(int i = 0; i < width; i++)
        if(!IsValidRow(sudokuBoard, i, width))
        {
            System.out.print("Invalid entry found \n (Row)" + "\t"+ i + "\n");
          //Do something - The row has repetitions
        }
        else{
            System.out.print("Row " +i + " is valid \n");
        }
    for(int j = 0; j < height; j++)
        if(!IsValidColumn(sudokuBoard, j, height))
        {
            System.out.print("(Column)" + j + "\n");
          //Do something - The columns has repetitions
        }
        else{
            System.out.print("Column " +j +" is valid \n");
        }
   for(int i=0; i<2; i++)
        if(!IsBlock1Valid(sudokuBoard,i, j)){
            System.out.print("hi");
        }

}

1 个答案:

答案 0 :(得分:2)

访问数组中的单元格应使用方括号,seen是一个数组:

seen[sudokuBoard[referenceColumn+i][referenceRow+j]]