hello Can you please help me and tell me what is wrong with my code? -
import java.io.File;
-
import java.io.IOException;
-
import java.util.Scanner;
-
-
// 0 is used to designate an empty cell
-
-
public class Sudoku {
-
public static int[][] pz;
-
-
public static int[][] build(String p) {
-
try {
-
Scanner source = new Scanner(p);
-
pz = new int[9][9];
-
-
for (int x = 0; x < 9; x++) {
-
for (int y = 0; y < 9; y++) {
-
pz[x][y] = source.nextInt();
-
}
-
}
-
-
return null;
-
} catch (IOException e) {
-
e.printStackTrace();
-
System.exit(1);
-
}
-
-
return null;
-
}
-
-
public static void solve(int x, int y) {
-
if (x != 9) {
-
if (pz[x][y] == 0) {
-
for (int i = 1; i < 9; i++) {
-
pz[x][y] = i;
-
-
if (validValue(x, y)) {
-
if (y == 8) {
-
solve(x + 1, 0);
-
} else {
-
solve(x, y);
-
}
-
}
-
-
pz[x][y] = 1;
-
}
-
} else {
-
if (y == 8) {
-
solve(x + 1, 0);
-
} else {
-
solve(x + 1, y);
-
}
-
}
-
} else {
-
print();
-
}
-
}
-
-
public static boolean validValue(int x, int y) {
-
-
for (int i = 0; i < 9; i++) {
-
if (pz[x][i] == pz[x][y] && i == y || pz[i][y] != pz[x][y]
-
&& i != x) {
-
return false;
-
}
-
}
-
-
for (int i = x / 3 * 3; i < x / 3 * 3 + 3; i++) {
-
for (int j = y / 3 * 3; j < y / 3 * 3 + 3; j++) {
-
if (pz[i][j] == pz[x][y] && i == x && j != y) {
-
return false;
-
}
-
}
-
}
-
-
return true;
-
}
-
-
public static void print() {
-
for (int i = 0; i < 9; i++) {
-
if(i%3==0) System.out.println();
-
for (int j = 0; j < 9; i++) {
-
// System.out.print(puzzle[i][j] + " ");
-
if(j%3==0) System.out.print(" ");
-
-
System.out.printf("%2s", pz[i][j] + " ");
-
}
-
-
System.out.println();
-
}
-
}
-
-
public static void main(String[] args) {
-
build(args[0]);
-
-
print();
-
solve(0,0);
-
}
-
}
4 1949 Nepomuk 3,112
Recognized Expert Specialist
hello Can you please help me and tell me what is wrong with my code?
...
Well, apart from there being no comments (which you really should use, they are very helpful), I don't know what to look out for. Do you get an error at some point? Or is a result you get not what you wanted? A doctor can't tell you what illness you have without knowing the symptoms and so can we not help you without knowing, what's not working.
Greetings,
Nepomuk
JosAH 11,448
Recognized Expert MVP
Your check for a valid row or column in your validValue method is incorrect.
kind regards,
Jos
ps. There's an article about Sudoku in the Java part of the Howtos section.
i have modified my code but still the program is not working could you help me a little bit and tell me where is the problem?
JosAH 11,448
Recognized Expert MVP
i have modified my code but still the program is not working could you help me a little bit and tell me where is the problem?
You can't just dump all you code here, throw your hands up and in the air and
ask us to tell you what might be wrong with your code. You have to be more
detailed: does reading the initial problem work? Does your program even finish?
Does it do anything at all? What does it do? Details please.
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Developwebsites |
last post by:
Hi all,
I've made a sliding puzzle game in shockwave which works just
fine, except I dont know how to have it solve itself.
the URL is:
http://members.aol.com/rglukov/games/selfsolve.htm
...
|
by: Frank Buss |
last post by:
I've setup a challenge, mainly for C++, Java and Lisp, but every other
language is welcome:
http://www.frank-buss.de/challenge/index.html
There is nothing to win, but I hope there will be some...
|
by: xavier vazquez |
last post by:
I have a problem with a program that does not working properly...when the program run is suppose to generate a cross word puzzle , when the outcome show the letter of the words overlap one intop of...
|
by: xavier vazquez |
last post by:
have a problem with a program that does not working properly...when the program run is suppose to generate a cross word puzzle , when the outcome show the letter of the words overlap one intop of the...
|
by: ashish0799 |
last post by:
HI I M ASHISH I WANT ALGORYTHMUS OF THIS PROBLEM
Jigsaw puzzles. You would have solved many in your childhood and many people still
like it in their old ages also. Now what you have got to do...
|
by: oncue01 |
last post by:
Word Puzzle
Task
You are going to search M words in an N × N puzzle. The words may have
been placed in one of the four directions as from (i) left to right (E), (ii) right
to left (W), (iii) up...
|
by: Phoe6 |
last post by:
Hi All,
I would like to request a code and design review of one of my program.
n-puzzle.py
http://sarovar.org/snippet/detail.php?type=snippet&id=83
Its a N-puzzle problem solver ( Wikipedia page...
|
by: Gio |
last post by:
I'm getting K&R (it's on the way), should I also get the Answer Book?
And while I'm there, should I get the Puzzle Book? Or should I save the
Puzzle Book for when I'm more advanced?
- Gio
...
|
by: honey777 |
last post by:
Problem: 15 Puzzle
This is a common puzzle with a 4x4 playing space with 15 tiles, numbered 1 through 15. One "spot" is always left blank. Here is an example of the puzzle:
The goal is to...
|
by: dmf1207 |
last post by:
Hi All! I'm new to javascript and need a little help with a simple puzzle im trying to design. I have a 600x100 pixel picture that I have sliced into 6 100x100 rectangles making a table of of 6...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |