Question: Write a Java program to create a 9 X 9 sudoku problem. A sample of a 9 x 9 sudoku board is given below: The

Write a Java program to create a 9 X 9 sudoku problem. A sample of a 9 x 9 sudoku
board is given below:
The rules for the sudoku game are:
i) Each row must contain the digits 1-9 without repetition
ii) Each column must contain the digits 1-9 without repetition
iii) Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without
repetition
Procedure:
1. Import java.util.Random package and use the nextInt() method of the Random
class to generate numbers between 1 and 9 for the sudoku board.
2. For each row, take a number from the user (between 4 and 6, both inclusive).
Then, randomly generate that number of distinct digits between 0 and 8(both
inclusive) and assign 0s to those corresponding cells of that row in the array. Forinstance, if the user types 4 for the first row, then generate four distinct digits
randomly using the nextInt() method of the Random class. If the four digits are 0,
3,5, and 8, then assign 0 to [0][0],[0][3],[0][5], and [0][8] cells. Similarly, assign
0s to specific cells from the 2nd to 9th rows. These 0s will represent empty cells.
3. Now, randomly generate distinct digits within the range 1 to 9 and assign them to
empty cells of nine rows and nine columns as per the rules of the sudoku board.
4. Repetition within a 3 X 3 block is allowed for this assignment.
5. You dont have to check whether the sudoku is solvable or not.
Hint:
1. nextInt(n) method returns a digit between 0 and (n-1). To generate a digit from 0
to 8 for a cell index, call nextInt(9) method. To generate a digit from 1 to 9, use
nextInt(9)+1.
2. First, fill in the empty cells of nine cells of the first row and first column with
distinct digits from 1 to 9. Then fill in the empty cells of the rest eight cells of the
second row and second column as per the sudoku rule, and so on.
DO NOT use any array-related built-in Java classes and methods. You can use
the Scanner class of Java to read the user input. The sample input/ output is given
below:
Sample input:
Enter the empty cell number from 4 to 6 for each row
Enter the number of empty cells of row 1: 6
Enter the number of empty cells of row 2: 5
Enter the number of empty cells of row 3: 6
Enter the number of empty cells of row 4: 6
Enter the number of empty cells of row 5: 5
Enter the number of empty cells of row 6: 4
Enter the number of empty cells of row 7: 6
Enter the number of empty cells of row 8: 5
Enter the number of empty cells of row 9: 6
Sample output:
530070000
600195000
098000060
800060003
400803001
703024006
060000280
000419005
000080079
 Write a Java program to create a 9 X 9 sudoku

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 Databases Questions!