Results 1 to 10 of 10
Thread: Update New to Java
- 04-08-2010, 01:11 AM #1
Member
- Join Date
- Apr 2010
- Posts
- 13
- Rep Power
- 0
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.;):)
-
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!
- 04-08-2010, 04:19 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
First of all, did you run this code and have a look at the results?
- 04-08-2010, 05:02 AM #4
Member
- Join Date
- Apr 2010
- Posts
- 13
- Rep Power
- 0
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.
- 04-08-2010, 05:11 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 04-08-2010, 05:46 AM #6
Member
- Join Date
- Apr 2010
- Posts
- 13
- Rep Power
- 0
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.
- 04-08-2010, 12:56 PM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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....
- 04-09-2010, 01:09 AM #8
Member
- Join Date
- Apr 2010
- Posts
- 13
- Rep Power
- 0
Oops sorry I meant my window is a 600 x 600 and the boxes are a 9x9.
I really hope that this clarifies everything.
- 04-09-2010, 09:33 AM #9
Senior Member
- Join Date
- Mar 2009
- Posts
- 105
- Rep Power
- 0
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? :pOkay 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.
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 09:37 AM.
- 04-09-2010, 11:54 AM #10
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Similar Threads
-
Update New to Java
By Jaguar1998 in forum EclipseReplies: 1Last Post: 04-08-2010, 02:14 AM -
Unwanted Java update
By Hummingbird in forum New To JavaReplies: 2Last Post: 02-10-2010, 10:18 AM -
JMX update of Java 1.6.0_13
By twinks in forum Advanced JavaReplies: 0Last Post: 10-07-2009, 02:13 PM -
using java dom to update file
By newbieal in forum New To JavaReplies: 6Last Post: 10-10-2008, 11:16 PM -
Java Crashes on Mac 10.3.9 not sure how to update
By patricknowow in forum New To JavaReplies: 1Last Post: 11-30-2007, 03:57 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks