okay, so i started on code for Sudoku on ready to program java ... very close to java. I was able to create a 2d array and display and change the variables. What i want to do now is to generate random numbers in the array. Numbers in between 1 and 9. and then i need to check for rows, columns and the boxes... i am new to arrays and i really need some help.
Code:
// The "Sudoku" class.
import java.awt.*;
import hsa.Console;
public class Sudoku
{
static Console c; // The output console
public static void main (String[] args)
{
c = new Console ();
final int ROWS = 9;
final int COLS = 9;
int row;
int col;
int newValue = 0;
/* row and col are what the user enters, to locate what place they want to change. New value is what
they want to change to*/
int[] [] board = new int [ROWS] [COLS];
//creates the array
c.println("");
c.println("");
c.println("");
while (newValue != -1) // entire loop prints ///////////////////////////////////all the numbers out
{
for (int i = 0 ; i < ROWS ; i++)
{
for (int j = 0 ; j < COLS ; j++)
{
c.print (" " + board [i] [j]);
}
c.println ("");
}
c.print ("Row: ");
row = c.readInt () - 1;
c.print ("Column: ");
col = c.readInt () - 1;
c.print ("change to: ");
newValue = c.readInt ();//inputs 4 location
if (newValue < 1 || newValue > 9 || row <0 || row > 8 || col < 0 ||col>8)
{
c.print ("your entry is invalid");
c.clear();
}
else
{
board [row] [col] = newValue;
c.print (board [row] [col]);
c.clear ();
}
}
}
} // this is all it does, please help!
// main method
// Sudoku class
Comment