Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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. For instance, 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: (20 points) Sample input: (Users inputs are shown in bold) 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: 530070000600195000098000060800060003400803001703024006060000280000419005000080079

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

25 Vba Macros For Data Analysis In Microsoft Excel

Authors: Klemens Nguyen

1st Edition

B0CNSXYMTC, 979-8868455629

More Books

Students also viewed these Databases questions

Question

Which of the following describes why scoping reviews are important?

Answered: 1 week ago