// Prints several lines and boxes made of stars. // Second version that uses parameterized methods. public class Stars2 { 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 for (int i = 1; i <= width; i++) { System.out.print("*"); } System.out.println(); // 2) middle empty part // (height - 2) times: // *, (width - 2) spaces, * for (int i = 1; i <= height - 2; i++) { System.out.print("*"); for (int j = 1; j <= width - 2; j++) { System.out.print(" "); } System.out.println("*"); } // 3) bottom line for (int i = 1; i <= width; i++) { System.out.print("*"); } System.out.println(); } // 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(" "); } } }