// Karanbir Singh // // Variation of Stars2 that adds a writeChars method to eliminate redundant // for loops. public class Stars3 { public static void main(String[] args) { line(13); line(7); line(35); box(10, 5); box(5, 6); } // Draws a line of stars of the given length. public static void line(int count) { writeChars('*', count); System.out.println(); } // Draws a box of stars of the given width and height. public static void box(int width, int height) { line(width); for (int line = 1; line <= height - 2; line++) { System.out.print("*"); writeChars(' ', width - 2); System.out.println("*"); } line(width); } // Writes given number of given character to current output line. public static void writeChars(char ch, int count) { for (int i = 1; i <= count; i++) { System.out.print(ch); } } }