Loops that pring checkerboard patterns?
807591Mar 16 2008 — edited Mar 20 2008I 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