Below is the syntax highlighted version of Diamond.java
from §1.3 Conditionals and Loops.
/************************************************************************* * Compilation: javac Diamond.java * Execution: java Diamond N * * Prints out a 2N+1-by-2N+1 diamond like the one below. * * % java Diamond 4 * . . . . * . . . . * . . . * * * . . . * . . * * * * * . . * . * * * * * * * . * * * * * * * * * * * . * * * * * * * . * . . * * * * * . . * . . . * * * . . . * . . . . * . . . . * *************************************************************************/ public class Diamond { 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 (Math.abs(i) + Math.abs(j) <= N) System.out.print("* "); else System.out.print(". "); } System.out.println(); } } }