// Variation of the Diamond program that replaces the global SIZE constant with // parameters to make generalized versions of drawDiamond and drawX that can // draw versions at different sizes. public class Diamond4 { public static void main(String[] args) { drawDiamond(8); drawDiamond(4); drawX(6); } public static void drawDiamond(int size) { upTriangle(size); downTriangle(size); } public static void drawX(int size) { downTriangle(size); upTriangle(size); } public static void upTriangle(int size) { for (int row = 0; row < size; row++) { writeStrings(size - 1 - row, " "); System.out.print("/"); writeStrings(2 * row, "."); System.out.println("\\"); } } public static void downTriangle(int size) { for (int row = size - 1; row >= 0; row--) { writeStrings(size - 1 - row, " "); System.out.print("\\"); writeStrings(2 * row, "."); System.out.println("/"); } } // prints count occurrences of text public static void writeStrings(int count, String text) { for (int i = 0; i < count; i++) { System.out.print(text); } } }