I'm trying to make a Java Soduku solver. I have some errors in my code, any help would be great. I have some errors on cells, fields, array list, integer generate numbers, and a couple errors with brackets. Thanks for your time and help!
package random;
import java.util.Collections;
public class Soduku {
static short row;
boolean check()
{
if(row==9)
{
}
return true;
}
boolean check2() {
if(cells[row[col]] != 0)
{
if(solve(col==8? (row+1): row, (col+1) % 9 ))
{
return true;
}
}
else {
Integer[] random = generateNumbers();
for(int i=0; i<9; i++)
{
if(!containedInRowCol(row, col, random && !containedIn3x3Box(row, col, random)))
{
cells[row] [col] = random;
fields[row] [col].setText(String.valueOf(random));
if(solve(col==8? (row +1) : row, (col +1) % 9))
return true;
else
{
cells[row] [col] = 0;
fields[row] [col].setText("");
}
}
}
}
}
return false;
private boolean containedIn3x3Box(int row, int col, int value)
{
int startRow = row/3 * 3;
int startCol= col/3 *3;
for(int i=startRow; i<startRow +3; i++)
for(int q=startCol; q<startCol +3; q++)
{
if(!(i==row && q==col))
{
if(cells [q] ==value)
{
return true;
}
}
}
return false;
}
private Integer[] generateNumbers()
{
ArrayList<Integer> random = new ArrayList<Integer>();
for(int i=0; i<9; i++)
random.add(i+1);
Collections.shuffle(random);
return random.toArray(new Integer[9]);
}
public static void main(String[] args) {
}
package random;
import java.util.Collections;
public class Soduku {
static short row;
boolean check()
{
if(row==9)
{
}
return true;
}
boolean check2() {
if(cells[row[col]] != 0)
{
if(solve(col==8? (row+1): row, (col+1) % 9 ))
{
return true;
}
}
else {
Integer[] random = generateNumbers();
for(int i=0; i<9; i++)
{
if(!containedInRowCol(row, col, random && !containedIn3x3Box(row, col, random)))
{
cells[row] [col] = random;
fields[row] [col].setText(String.valueOf(random));
if(solve(col==8? (row +1) : row, (col +1) % 9))
return true;
else
{
cells[row] [col] = 0;
fields[row] [col].setText("");
}
}
}
}
}
return false;
private boolean containedIn3x3Box(int row, int col, int value)
{
int startRow = row/3 * 3;
int startCol= col/3 *3;
for(int i=startRow; i<startRow +3; i++)
for(int q=startCol; q<startCol +3; q++)
{
if(!(i==row && q==col))
{
if(cells [q] ==value)
{
return true;
}
}
}
return false;
}
private Integer[] generateNumbers()
{
ArrayList<Integer> random = new ArrayList<Integer>();
for(int i=0; i<9; i++)
random.add(i+1);
Collections.shuffle(random);
return random.toArray(new Integer[9]);
}
public static void main(String[] args) {
}