// Prints several lines and boxes made of stars. // Third version in which printBox method calls printStars and printSpaces. public class Stars3 { public static void main(String[] args) { // print several lines of stars printStars(13); printStars(7); printStars(35); 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 printStars(width); // 2) middle empty part for (int i = 1; i <= height - 2; i++) { System.out.print("*"); printSpaces(width - 2); System.out.println("*"); } // 3) bottom line printStars(width); } // Prints the given number of stars plus a line break. public static void printStars(int howMany) { for (int i = 1; i <= howMany; i++) { System.out.print("*"); } System.out.println(); } // Prints the given number of spaces. public static void printSpaces(int count) { for (int i = 1; i <= count; i++) { System.out.print(" "); } } }