Results 1 to 3 of 3
  1. #1
    ShortIt is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default Simple Checkerboard

    Hi everyone,

    I believe to have a simple problem, which I can not determine the solution for. I need to write a program that displays a 8*8 checkerboard.

    Below is an illustration for one of the ROWS and there should be 7 more below it. Hopefully the idea is pretty simple.

    *******************************
    * * * * * * * * *
    * * * * * * * * *
    * * * * * * * * *
    *******************************

    My original assignment asked for to use 2 dimensional arrays to print this.
    Before I start with two dimensional arrays, I wanted to figure the logic of this using if statement and for loop.

    SO i simply wrote a code in which how many different ways I modify would not print that diahgram. I need someone to look at it and tell me what am I doing wrong.

    PROBLEM = the main problem is that when the for loop goes over the counter position (0) and (1) it does not increment the (VARIABLE (c)) as shown in the code below.

    CODE=

    class Trial

    {
    public static void main (String [] args)
    {

    //variables
    int count = 0;




    for (int c =0; c <=33; c++)
    {

    if (count == 0)
    {
    System.out.println(c + " ************************************************* " + count);
    count++;
    }
    if (count > 0)
    {
    System.out.println(c + " * * * * * * * * * " + count);
    count++;

    if (count == 4)
    {
    count = 0;
    }

    }


    }


    }


    }



    __________________________________________________ ____________

    This should be a NO NO

    <variable (c) value>0 ******************************** 0<counter value>
    <variable (c) value>0 * * * * * * * * * 1<counter value>




    Thanks for looking at this problem

  2. #2
    hosscomp is offline Member
    Join Date
    Oct 2010
    Posts
    63
    Rep Power
    0

    Default

    You probably meant:
    Java Code:
    if ( c == 0){
    ...
    count++;
    }
    else if ( c == 4){
    ..
    count = 0;
    }
    else {
    ...
    count++
    }
    This way it only goes throuth only one of the conditions each loop.

  3. #3
    ShortIt is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

Similar Threads

  1. Checkerboard Program
    By Jnoobs in forum New To Java
    Replies: 9
    Last Post: 09-21-2010, 03:46 AM
  2. New simple application using a simple database
    By webbusiness23 in forum New To Java
    Replies: 9
    Last Post: 08-03-2009, 02:55 AM
  3. Replies: 3
    Last Post: 07-23-2009, 07:45 AM
  4. Replies: 1
    Last Post: 07-22-2009, 10:10 PM
  5. Replies: 2
    Last Post: 05-04-2008, 05:27 PM

Posting Permissions

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