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

    Default Update New to Java

    Okay I would like to let everyone know that I am trying to figure out how to make my code work to where it will check and allow my soduku puzzle to be one that is legal by the rules of soduku.

    I am using Eclipse and when ever I type for for the forloop (which beinging a a green horn to Java I do not understand what this fully does.
    I would like to see guidance for the code and if someone knows of a very good Java book that I could get that would help me understand Java well for a greenhorn let me know because I really need to know.

    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;
    }
    }}}I would hope that everyone could help me out on this and those who do thank you so much and also thanks for suggesting java books to help me understand the language better.;):)

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

    Default

    Duplicate thread closed. Please let's keep only one thread per question. Thank you for your cooperation. Also, please have a look at the FAQ (or my signature links) regarding code tags. Much luck!

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

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

    Default reply

    When I have ran the program it shows a grid in a window of about 600 by 600 it is a gui and so I think that is why I am having such a headache with this being my first programming language.

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

    Default

    Are you talking about the code segment you've post before? Seems there is no connection with what you've post and what you are saying now.

  6. #6
    Jaguar1998 is offline Member
    Join Date
    Apr 2010
    Posts
    13
    Rep Power
    0

    Default New to Java

    I am confused on the first question for which you were asking.

    I am trying to create a for loop in an attempt that I can stop the same numbers in the same column and row.

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

    Default

    According to your code segment above you have 9 X 9 block simply. Later you said that you've a grid of 600 by 600....

  8. #8
    Jaguar1998 is offline Member
    Join Date
    Apr 2010
    Posts
    13
    Rep Power
    0

    Default

    Oops sorry I meant my window is a 600 x 600 and the boxes are a 9x9.

    I really hope that this clarifies everything.

  9. #9
    porchrat is offline Senior Member
    Join Date
    Mar 2009
    Posts
    105
    Rep Power
    0

    Default

    Okay I would like to let everyone know that I am trying to figure out how to make my code work to where it will check and allow my soduku puzzle to be one that is legal by the rules of soduku.

    I am using Eclipse and when ever I type for for the forloop (which beinging a a green horn to Java I do not understand what this fully does.
    I would like to see guidance for the code and if someone knows of a very good Java book that I could get that would help me understand Java well for a greenhorn let me know because I really need to know.
    If you are using eclipse could you please try formatting the code you post correctly so that we don't have to read something all squeezed into the margin? Why stop there why not remove the whitespace altogether? :p

    Seriously though the for loop will just iterate until the conditions you have stated are evaluated true. There are plenty of tutorials online to help you until you decide on a book. Here is a Sun tutorial for "for loops" which will help you understand them a little better:

    The for Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)

    I quite like Absolute Java as a book because it starts from the beginning with object orientation and basic constructs like loops and switches and works through to somewhere in GUIs if I am not mistaken, but it is a fair amount of reading.

    EDIT: I also feel I should warn you now that there is something you have not yet considered with that code. Just checking that the rows and columns don't contain duplicate numbers is not enough to ensure that the sudoku puzzle is legitimate. You also need to check every single one of the 9 3x3 blocks in the puzzle for duplicates.
    Last edited by porchrat; 04-09-2010 at 10:37 AM.

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

    Default

    Quote Originally Posted by Jaguar1998 View Post
    Oops sorry I meant my window is a 600 x 600 and the boxes are a 9x9.

    I really hope that this clarifies everything.
    Yeah, now it's much clear.

Similar Threads

  1. Update New to Java
    By Jaguar1998 in forum Eclipse
    Replies: 1
    Last Post: 04-08-2010, 03:14 AM
  2. Unwanted Java update
    By Hummingbird in forum New To Java
    Replies: 2
    Last Post: 02-10-2010, 11:18 AM
  3. JMX update of Java 1.6.0_13
    By twinks in forum Advanced Java
    Replies: 0
    Last Post: 10-07-2009, 03:13 PM
  4. using java dom to update file
    By newbieal in forum New To Java
    Replies: 6
    Last Post: 10-11-2008, 12:16 AM
  5. Java Crashes on Mac 10.3.9 not sure how to update
    By patricknowow in forum New To Java
    Replies: 1
    Last Post: 11-30-2007, 04:57 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
  •