Re: Sudoku: wrong output?
Can you add comments explaining what is wrong with the output and post what it should be.
Re: Sudoku: wrong output?
After a quick look, I don't believe you ever check to see whether or not the grid position already has a value.
Re: Sudoku: wrong output?
Correct answer should be:
5 9 6 | 3 1 7 | 2 4 8
1 4 3 | 6 2 8 | 7 9 5
8 7 2 | 4 5 9 | 3 1 6
--------------------
2 1 4 | 5 3 6 | 9 8 7
6 5 8 | 7 9 2 | 1 3 4
9 3 7 | 8 4 1 | 5 6 2
--------------------
7 6 9 | 1 8 5 | 4 2 3
4 8 1 | 2 7 3 | 6 5 9
3 2 5 | 9 6 4 | 8 7 1
How could I check if the Grid[][] already has a value?
Re: Sudoku: wrong output?
Where do you read in the data to fill the grid array?
Add this line to the read() method right after the end of the for(j) loop's ending } and still inside the for(i) loop:
Code :
System.out.println(i + " " +Arrays.toString(Grid[i]));
It will show the contents of the array as it is read in so you can verify that the program is reading the file correctly.
Re: Sudoku: wrong output?
Ok I did that and I saw it doesnt read the last row of the sudoku...
Also, in the main I called the method read() but now it doesnt want to go back to main(). It doesnt give me an error, it just loops about 30 times or so in read() and then stops.
Re: Sudoku: wrong output?
Add another println statement in the readInteger() method that prints out the value of word after it is returned from the readWord method.
Re: Sudoku: wrong output?
It prints out "x x x | x x x | x x x ".
Re: Sudoku: wrong output?
Is that all? It should print out all of the input file.
And the output should look like this:
x
x
x
|
x
x
x
|
x
x
x
One word on each line.
Re: Sudoku: wrong output?
Yes that is what I meant, sorry about that. But how is that supposed to help figure out whats the problem?
Re: Sudoku: wrong output?
Quote:
how is that supposed to help figure out whats the problem?
It's called debugging,
It helps you find where the problem is. Where does the printing stop? What is the last thing printed?
What remains in the file to be read and printed?
Re: Sudoku: wrong output?
Quote:
Originally Posted by
Norm
It's called debugging,
It helps you find where the problem is. Where does the printing stop? What is the last thing printed?
What remains in the file to be read and printed?
This is the output. Final row 8 is not read.
3
x
x
x
|
x
x
x
|
x
x
x
0 [0, 0, 0, 0, 0, 0, 0, 0, 0]
x
1
x
|
6
2
x
|
x
9
x
1 [0, 1, 0, 6, 2, 0, 0, 9, 0]
x
x
2
|
x
x
9
|
3
1
x
2 [0, 0, 2, 0, 0, 9, 3, 1, 0]
---------------------
x
x
4
|
x
x
6
|
x
8
x
3 [0, 0, 4, 0, 0, 6, 0, 8, 0]
x
x
8
|
7
x
2
|
1
x
x
4 [0, 0, 8, 7, 0, 2, 1, 0, 0]
x
3
x
|
8
x
x
|
5
x
x
5 [0, 3, 0, 8, 0, 0, 5, 0, 0]
---------------------
x
6
9
|
1
x
x
|
4
x
x
6 [0, 6, 9, 1, 0, 0, 4, 0, 0]
x
8
x
|
x
7
3
|
x
5
x
7 [0, 8, 0, 0, 7, 3, 0, 5, 0]
x
x
x
|
x
x
x
|
x
x
Re: Sudoku: wrong output?
Now answer these questions I asked:
Where does the printing stop? What is the last thing printed?
What remains in the file to be read and printed?
Quote:
now it doesnt want to go back to main().
Does that mean the program is in a loop? Would the answers to the above questions point to where the program is looping?
Re: Sudoku: wrong output?
The program stops after the above output is printed and its not a loop or an error, its just stops. The last row 0 [0, 0, 0, 0, 0, 0, 0, 0, 0] is supposed to be printed.
In read(), in the first for loop I changed i < N to i<N-1 just to see what would happen and the program ran fine but of course the output of the sudoku was false.
Thanks for the help!
Re: Sudoku: wrong output?
Quote:
I changed i < N to i<N-1
That means you are not reading the last line of the file. What if there are numbers on the last line?
That is not the solution. You need to find the endless looping and fix it.