# Simple Checkerboard

• 01-18-2011, 09:14 PM
ShortIt
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
• 01-18-2011, 11:53 PM
hosscomp
You probably meant:
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.
• 01-19-2011, 05:03 AM
ShortIt
Thanks for your help, I did work....