This is the syntax highlighted version of Ex.java.
/*************************************************************************
* Compilation: javac Ex.java
* Execution: java Ex N
*
* Prints out an X of radius N like the one below.
*
* % java Ex 5
* * . . . . . *
* . * . . . * .
* . . * . * . .
* . . . * . . .
* . . * . * . .
* . * . . . * .
* * . . . . . *
*
*************************************************************************/
public class Ex {
public static void main(String[] args) {
int N = Integer.parseInt(args[0]);
for (int i = -N; i <= N; i++) {
for (int j = -N; j <= N; j++) {
if ((i == -j) || (i == j)) System.out.print("* ");
else System.out.print(". ");
}
System.out.println();
}
}
}
Last updated: Wed Feb 11 18:07:23 EST 2004
.
Copyright © 2004, Robert Sedgewick and Kevin Wayne.