public void solveNext(int[][] matrix,boolean[][]change, int row, int col, int j) throws Exception{ col++; if(col == 9){ row++; col = 0; } while(change[col][row]== false ){ col++; if(col == 9){ row++; col = 0; } } for(int k=j; k<=9;k++){ count++; if(count >100000){ System.out.println(count); } matrix[row][col] = k; boolean chkk = chk(matrix,row,col); if(chkk &&(row == 8 && col == 8)){ throw new Exception(); }else if(chkk) { solveNext(matrix,change,row,col, 1); } } matrix[row][col] = -1; return; }