Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: find first empty cell?

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    8
    My Mood
    Where
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default find first empty cell?

    What i want to do is use a for-loop to find the first empty cell in a 2D array and put a value in it. However, my code applies the loop to all empty cells in the array. What am i doing wrong here? I hope for a quick reply.
    for (int row = 0; row < GRIDSIZE; row++) {
                    for (int col = 0; col < GRIDSIZE; col++) {
                        if (isEmpty(row, col) == false) {
                            printIt(); 
                        } else {
                            setCell(row, col, 1);

    Any help would be appreciated.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,342
    My Mood
    Hungover
    Thanks
    143
    Thanked 625 Times in 536 Posts

    Default Re: find first empty cell?

    Where is the code that stops you from continuing the loop after you find the empty cell?

    You might want to read this: Branching Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)
    Or this: The while and do-while Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,342
    My Mood
    Hungover
    Thanks
    143
    Thanked 625 Times in 536 Posts

    Default Re: find first empty cell?

    Ugh, but it seems I was wasting my time, as the OP already received an answer elsewhere: find first empty cell? - Java Forums

    Read this: The problems with cross-posting
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: find first empty cell?

    Please keep us up to date with this same thread on different forums prettynew. This is cross posting.
    It's important to make sure you do this so you continue to receive quality responses here in the future.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  5. #5
    Junior Member
    Join Date
    Mar 2011
    Posts
    8
    My Mood
    Where
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: find first empty cell?

    I apologize for my ignorance of the forums etiquette. In my defense id like to say that i was chasing a deadline and i wanted to increase my chances to find a solution as soon as i could.
    I will have that in mind from now on.

Similar Threads

  1. how to pass value of table cell as parameter/attribute
    By ajincoep in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: February 8th, 2011, 08:51 AM
  2. How to start writing Java Apps for Cell Phones?
    By Jchang504 in forum Java ME (Mobile Edition)
    Replies: 7
    Last Post: January 10th, 2011, 04:11 AM
  3. Removing the middle cell
    By Shyamz1 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 7th, 2010, 12:35 PM
  4. JTable prepareRenderer changes all cell colors
    By BrettStuart in forum AWT / Java Swing
    Replies: 9
    Last Post: July 21st, 2010, 02:51 AM
  5. How to create a database in my cell phone?
    By Viggopiano in forum Java ME (Mobile Edition)
    Replies: 2
    Last Post: July 12th, 2010, 07:26 AM