// Variation of the Diamond program that uses a parameterized writeStrings // method to eliminate the loop redundancy. public class Diamond3 { public static final int SIZE = 8; public static void main(String[] args) { upTriangle(); downTriangle(); } public static void upTriangle() { for (int line = 0; line < SIZE; line++) { writeStrings(SIZE - 1 - line, " "); System.out.print("/"); writeStrings(2 * line, "."); System.out.println("\\"); } } public static void downTriangle() { for (int line = SIZE - 1; line >= 0; line--) { writeStrings(SIZE - 1 - line, " "); System.out.print("\\"); writeStrings(2 * line, "."); 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); } } }