// Prints several lines and boxes made of stars. // Fourth and final version with printCharacter method. public class Stars4 { public static void main(String[] args) { // print several lines of stars printCharacter("*", 13); System.out.println(); printCharacter("*", 7); System.out.println(); printCharacter("*", 35); System.out.println(); System.out.println(); // print several boxes of stars printBox(10, 3); printBox(5, 4); printBox(20, 7); } // Prints a box of stars of the given size. public static void printBox(int width, int height) { // 1) top line printCharacter("*", width); System.out.println(); // 2) middle empty part for (int i = 1; i <= height - 2; i++) { System.out.print("*"); printCharacter(" ", width - 2); System.out.println("*"); } // 3) bottom line printCharacter("*", width); System.out.println(); } // Prints the given number of occurrences of the given text. public static void printCharacter(String character, int howMany) { for (int i = 1; i <= howMany; i++) { System.out.print(character); } } }