Question: I don't know how to fix this code for it to print a sudoku puzzle with it saving the solution of the puzzle as a

I don't know how to fix this code for it to print a sudoku puzzle with it saving the solution of the puzzle as a corresponding array. The code is in Java.
public class Sudoku
{
int[]mat[];
int N; //number of columns/rows.
int SRN; //square root of N
int K; //No.Of missing digits
//Constructor
Sudoku(int N,int K)
{
this.N =N;
this.K =K;
//Compute square root of N
Double SRNd =Math.sqrt(N);
SRN =SRNd.intValue();
mat =new int[N][N];
}
//Sudoku Generator
public void fillValues()
{
//Fill the diagonal of SRN x SRN matrices
fillDiagonal();
//Fill remaining blocks
fillRemaining(0,SRN);
//Remove Randomly K digits to make game
removeKDigits();
}
//Fill the diagonal SRN number of SRN x SRN matrices
void fillDiagonal()
{
for (int i =0; ii==j
fillBox(i,i);
}
//Returns false if given 3x 3block contains num.
boolean unUsedInBox(int rowStart, int colStart, int num)
{
for (int i =0; i=N && i=N && j>=N)
return true;
if (i <SRN)
{
if (j <SRN)
j =SRN;
}
else if (i <N-SRN)
{
if (j==(int)(i/SRN)*SRN)
j =j +SRN;
}
else
{
if (j ==N-SRN)
{
i =i +1;
j =0;
if (i>=N)
return true;
}
}
for (int num =1; num<=N; num++)
{
if (CheckIfSafe(i,j,num))
{
mat[i][j]=num;
if (fillRemaining(i,j+1))
return true;
mat[i][j]=0;
}
}
return false;
}
//Remove the K no.of digits to
//complete game
public void removeKDigits()
{
int count =K;
while (count !=0)
{
int cellId =randomGenerator(N*N)-1;
//System.out.println(cellId);
//extract coordinates i and j
int i =(cellId/N);
int j =cellId%N;
//System.out.println(i+""+j);
if (mat[i][j]!=0)
{
count--;
mat[i][j]=0;
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!