Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Loops that pring checkerboard patterns?

807591Mar 16 2008 — edited Mar 20 2008
I am trying to write a program called that takes a command line argument N and uses a loop within a loop to print out a two-dimensional N-by-N checkerboard pattern with alternating periods and asterisks.

This is my code so far. I am not sure what I am doing wrong..

I am trying to get the pattern to print like this:

java CheckerboardPattern 5
* . * . * .
. * . * . *
* . * . * .
. * . * . *
* . * . * .

public class CheckerboardPattern {

public static void main(String[] args) {
int N = Integer.parseInt(args[0]);

for (int i = 1; i <= N; i++) {
System.out.print("* ");
for (int j = 1; j <= N; j++)

if (i / j == 1)
System.out.print("* ");
else
System.out.print(". ");

System.out.println();
}
}
}


Thanks in advance to anyone who can help...you guys..AND gals are great for everything you do....
Regards.

Edited by: jrprince21 on Mar 16, 2008 6:28 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 17 2008
Added on Mar 16 2008
4 comments
906 views