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

  Scientific management and stakeholder or sustainability

Centralization, contingency, decentralization, efficiency, mechanistic, organic, organizational behavior, scientific management, stakeholder, or sustainability

  Identify information needs in various community settings

Community Information Services-Level-Semester 2, Year 1-National Council for Higher Education- BACHELOR OF LIBRARY AND INFORMATION SCIENCE.

  What single question can you ask a person

assume you were in a country where each person was either a truth teller or a liar. (A truth teller always tells the truth, a liar always lies.) What single question could you ask a person that would allow you to detect whether that person was a t..

  Ask the name of the buyer and the number of shares bought

Write a program in java that asks the name of the buyer and the number of shares bought.

  Write down a 1400- to 1750-word paper explaining how to

write a 1400- to 1750-word paper describing how to formulate and present the business case for technology

  Write a program that asks the user to enter the size

Write a program that asks the user to enter the size for an array (greater than 0) and fills the array with a set of random numbers between 1 and the number.

  What a test plan document is used for

You're telling a friendy'family member who is not familiar with a technology project about your milestones defined in the test plan. How would you explain

  Calculate the squares and cubes of all integers from 1 to 10

Write a Java program to calculate the squares and cubes of all integers from 1 to 10. Align the printout as in the sample output.

  Develop a sales-tracking program that enables a company

Develop a sales-tracking program that enables a company to keep track of its sales force's performance by quarter.

  Write a program that asks the user to input a matrix

Write a program that asks the user to input a 3 X 3 matrix of integers, a row at a time.

  What are the three main types of shift keying

What are the three main types of shift keying? What is meant by the sampling rate of analog data? What are the differences among EBCDIC, ASCII, and Unicode?

  Make a product pitch for your selected product

Make a product pitch for your selected product to present to potential stakeholders and Analysis of how your solution is similar to or different from existing

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