Results 1 to 4 of 4
  1. #1
    Jaguar1998 is offline Member
    Join Date
    Apr 2010
    Posts
    13
    Rep Power
    0

    Default Stuck new to Java

    I am trying to do the soduku puzzle in Eclipse and am wonder how to do the checking here is a preview of my code and comments

    package SUDUKO;
    import java.awt.GridLayout;
    import java.util.Random;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    public class Suduko
    {
    private JTextField[][]cells;
    int[] variable1r = new int[9];
    int[] variable2r = new int[9];
    int[] variable3r = new int[9];
    int[] variable4r = new int[9];
    int[] variable5r = new int[9];
    int[] variable6r = new int[9];
    int[] variable7r = new int[9];
    int[] variable8r = new int[9];
    int[] variable9r = new int[9];

    public static void main( String[]args )
    {
    try
    {
    Suduko suduko = new Suduko();
    suduko.init();
    } catch (Exception e)
    {
    e.printStackTrace();
    }
    }
    private void init()
    {

    cells = new JTextField[9][9];

    JPanel panel = new JPanel();

    panel.setLayout( new GridLayout( 9, 9, 5, 5 ) );

    for (int i = 0; i < 9; i++)
    {
    for (int j = 0; j < 9; j++)
    {
    cells[i][j] = new JTextField();
    panel.add( cells[i][j] );
    }
    }

    JFrame frame = new JFrame();
    frame.add( panel );
    frame.setSize( 600, 600 );
    frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    frame.setVisible( true );

    initGame();
    }

    private void initGame()
    {
    Random r = new Random( 9 );
    for (int i = 0; i < 9; i++)
    {
    for (int j = 0; j < 9; j++)
    {
    int randomValue = r.nextInt( 9 ) + 1;
    if (IsValid( i, j, randomValue ))
    {
    cells[i][j].setText( String.valueOf( randomValue ) );
    } else
    {
    j--;
    }
    }
    }
    }
    private boolean IsValid( int row, int column, int value )
    {
    System.out.println( "Checking " + row + " " + column + " for " + value );
    {
    {
    return true;
    }
    }}}
    if(int=i++ then i= 2 then i!=2);
    //trying to create an if statement in the attempt of trying to avoid duplicate numbers in the randomizer
    //would like to create it but don't quite know how to get to this point of the program.
    //How would I go about doing this am I on the right track?
    // possible line of code to use is a for loop.

    for(int=i then i!=2);
    //for loop will cause it to repeat till finished but need it to be for three things column rows and 3x3 but how?
    {
    }Thanks to everyone for their help and info any links or help would be great.

  2. #2
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Another new thread? Here's some help:

    1. Learn how to find your original thread, and post in that one.
    2. Learn how to use CODE tags.
    3. Learn how to spell "Sudoku".

    Do those things and format your code so that it is readable, and you may get the help you want.

    -Gary-

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Locking. Come on Jaguar.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by gcalvin View Post
    Another new thread? Here's some help:

    1. Learn how to find your original thread, and post in that one.
    2. Learn how to use CODE tags.
    3. Learn how to spell "Sudoku".

    Do those things and format your code so that it is readable, and you may get the help you want.

    -Gary-
    Thumbs up. :)

Similar Threads

  1. I'm stuck help!!!
    By nobody58 in forum Advanced Java
    Replies: 2
    Last Post: 03-18-2010, 02:52 PM
  2. Replies: 5
    Last Post: 09-16-2009, 01:36 PM
  3. Kinda stuck of learning Java
    By jurka in forum New To Java
    Replies: 2
    Last Post: 02-14-2009, 04:00 PM
  4. Replies: 2
    Last Post: 12-10-2008, 04:40 PM
  5. Stuck in need of help!
    By Zombie_Leg! in forum New To Java
    Replies: 1
    Last Post: 09-23-2008, 02:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •