Java sudoku generator not working correctly

左心房为你撑大大i 提交于 2019-12-05 18:53:36

It's not enough that a row, column or section are valid. They ALL MUST be valid. So, change this line:

if (checkRow(num, x) == true || checkCol(num, y) == true || checkSection(num, x, y) == true) 

with

if (checkRow(num, x) == true && checkCol(num, y) == true && checkSection(num, x, y) == true) 

or just simple

if (checkRow(num, x) && checkCol(num, y) && checkSection(num, x, y)) {

There might be additional errors, but this line is clearly wrong:

if (checkRow(num, x) == true || checkCol(num, y) == true
                        || checkSection(num, x, y) == true) {

You should use && (boolean AND) here instead of || (boolean OR).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!