我正在编写Sudoku解算器,我的老师建议我使用3d数组,因为我从来没有使用过3D数组;我无法弄清楚如何创建循环遍历行和遍历列。你会如何去做这件事?通过3d数组迭代?
编辑:我想出了如何遍历每第三列/行,并希望我应该能够最终完成其他六个,但我是否朝着正确的方向前进?
int[][][] = board[9][3][3];
public boolean columnCheck(int[][][] board)
{
boolean filled = false;
for(int i = 0; i < board.length; i++)
{
for(int j = 0; j < board[0].length; j++)
{
System.out.println(board[i][j][0]);
}
}
return true;
}
public boolean rowCheck(int[][][] board)
{
boolean filled = false;
for(int i = 0; i < board.length; i++)
{
for(int j = 0; j < board[0].length; j++)
{
System.out.println(board[i][0][j]);
}
}
return true;
提示:'board.length'会给你9 ...如果你使用'board [0]'给你一个'int [] []'。如果你知道如何处理二维数组,那么你应该很好... –