Java program to create a 9 x 9 sudoku problem

Assignment Help Computer Engineering
Reference no: EM133694939

1. 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 2 nd 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 don't 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.
Sample input: (User's 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:
5 3 0 0 7 0 0 0 0
6 0 0 1 9 5 0 0 0
0 9 8 0 0 0 0 6 0

8 0 0 0 6 0 0 0 3
4 0 0 8 0 3 0 0 1
7 0 3 0 2 4 0 0 6
0 6 0 0 0 0 2 8 0
0 0 0 4 1 9 0 0 5
0 0 0 0 8 0 0 7 9

Reference no: EM133694939

Questions Cloud

Develop a data dictionary : Develop a Data Dictionary (before the actual database development). Which components of the databases would you include in the Data Dictionary for a facility
List the advantages of having the semantic markup : What is html ?Who sets the specification (or recommendations) html ? 2) List the advantages of having the semantic markup in an html document
Calculates the total price for any amount of items : Write a formula in cell B9 that calculates the total price for any amount of items input in a specific cell (in this case, cell B8)
How do they deliver the service to your location : What type of cabling is used to deliver your current internet service? What is the min and max speed and prices offered through this service?
Java program to create a 9 x 9 sudoku problem : 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
What are other systems of communication that work : What are other systems of communication that work like languages a la Saussure and Peirce? Do they have connection with each other? Do they have the connection
Identify one sustainable development goal : Sustainable Development Goal: Identify one Sustainable Development Goal (SDG) that aligns with the issue and the proposed intervention.
Demonstrate that you can use the devices : Demonstrate that you can use the devices in the right way when you complete each of these three observations
Why is bedside handover recommended as best practice : What role does the disposition checklist play in supporting a safe patient journey? Why is bedside handover recommended as best practice?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd