Hello, I was wondering if anyone could look at my code and possibly tell me where I am going wrong. It seems this has confused nearly everyone in my class and we cannot seem to figure this out. I have posted the objective that has to be accomplished in the attachments. Also this is what my code looks like (I'm sorry if there is a special way to link it, brand new to this :/ ) But basically what happens is every time I run this, I get this result:
Result:Basically I need the "0's" to be replaced by numbers that are not zero but less than 10 (1-9) and a number cannot be repeated next to each other unless that number comes from the original sudoku puzzle. So I cannot have like 1 1 4 because the 1 did replace the 0's but it was repeated next to each other.1 3 4 2 5 7 3 9 0
0 2 0 5 3 0 0 4 0
0 0 3 0 0 4 0 0 5
6 0 0 4 0 0 5 0 0
0 7 0 1 5 0 0 6 0
0 0 8 0 0 6 0 0 7
8 0 0 9 0 0 7 0 0
0 9 0 0 1 0 0 8 0
0 0 1 0 0 2 0 0 9
This is the Original: 0's need to be replaced with numbers between 1 and 9
1 0 4 2 0 0 3 0 0
0 2 0 5 3 0 0 4 0
0 0 3 0 0 4 0 0 5
6 0 0 4 0 0 5 0 0
0 7 0 1 5 0 0 6 0
0 0 8 0 0 6 0 0 7
8 0 0 9 0 0 7 0 0
0 9 0 0 1 0 0 8 0
0 0 1 0 0 2 0 0 9
import java.util.Scanner;
import java.io.*;
public class sudoku
{
private int x;
public sudoku()
{
x=0;
}
public static void main(String [] args) throws IOException {
int i=0;
File f = new File("single");
Scanner input = new Scanner(f);
int[]digit = new int[81];
while (input.hasNext())
{
digit[i]= input.nextInt();
i++;
}
for(int x=0;x<i;x++){
if(digit [x] == 0)
{
for(int y=1;y<10;y+=2)
{
int z;
for(z=0;z<x;z++)
{
if(y== digit [z])
break;
}
if(x==z){
digit[x]=y;
break;
}
}
}
if(x%9==0)
System.out.println("");
System.out.print(digit[x]+" ");
}
}
}