I just wana ask u about how to write a program that prints 2 dimensional N by N pattern with alternating spaces and asterisks.
Two dimensional pattern question
Collapse
X
-
Originally posted by mia023I just wana ask u about how to write a program that prints 2 dimensional N by N pattern with alternating spaces and asterisks. -
Originally posted by r035198xPlease read the posting guidelines before posting further.Comment
-
Originally posted by mia023can u just give me some hints Please
giveaway:
[code=java]
private static boolean isStar(int x, int y) { return true; }
private static void square(int N) {
for (int x= 0; x < N; x++) {
for (int y= 0; y < N; y++)
System.out.prin t(isStar(x, y)?'*' : ' ');
System.out.prin tln();
}
}
[/code]
The isStar() method returns true when at a certain position x, y a star should be
printed; otherwise it returns false. My implementation is a dummy implementation.
The square() method prints a square of size N. It consults the isStar() method for
every position x,y whether or not it should print a star or a space.
Now all you have to do is come up with a correct implementation of the isStar()
method.
kind regards,
JosComment
Comment