我目前正在制作一个数独程序,但是我当前的代码似乎让我失望。如果一行多次包含相同的数字,下面的脚本应该打印出“不一致的数独谜题”,但遗憾的是它没有......我尝试了几种不同的尝试,但都没有成功。
public void checkRow() {
int count = 0;
for(int j = 0; j < list.size(); j++) {
for(int a = 1; a < 10; a++) {
for (int i=0; i < list.get(j).length(); i++) {
if(list.get(j).charAt(i) == a) {
count++;
if(count >= 2) {
System.out.println("Inconsistent sudoku puzzle");
count = 0;
}
}
}
count = 0;
}
}
}
这是我所有错误检查的集合:
public void errorCheck() {
this.checkRow();
this.checkColumn();
this.checkBox();
}
在这里,我将它加载到我的 main.js 中。代码要复杂得多,但这些应该是涉及问题的部分。
public static void main(String[] args) throws Exception {
Sudoku s = new Sudoku("C:\\Users\\caspe\\Downloads\\Sudoku001.sdk");
s.printBoard();
s.errorCheck();
s.getNum();
while(getNum() > 0) {
System.out.println("Next move, please (row , column , value )");
Scanner scanner = new Scanner(System.in);
int row = scanner.nextInt();
int column = scanner.nextInt() ;
int value = scanner.nextInt();
if (s.moves(row, column, value)); {
s.errorCheck();
}
s.printBoard();
}
}
慕容森
慕村225694
宝慕林4294392
动漫人物
随时随地看视频慕课网APP
相关分类