// Simple program to draw three diamonds of varying sizes. public class Diamond4 { public static void main(String[] args) { drawDiamond(4); drawDiamond(6); drawDiamond(8); } // draws one diamond of the given size public static void drawDiamond(int size) { for (int row = 1; row <= size; row++) { drawRow(row, size, "/", "\\"); } for (int row = size; row >= 1; row--) { drawRow(row, size, "\\", "/"); } } // This is a helper method for the drawDiamond method. It takes a row // number and size and the appropriate slash characters (either \/ or /\). public static void drawRow(int row, int size, String s1, String s2) { drawStrings(size - row, " "); drawStrings(1, s1); drawStrings(2 * row - 2, "."); drawStrings(1, s2); System.out.println(); } // prints count occurrences of text to System.out public static void drawStrings(int count, String text) { for (int i = 1; i <= count; i++) { System.out.print(text); } } }