// Zorah Fung, CSE 142 // This program prints out several lines of stars of various lengths // and several boxes of stars of various widths and heights // Note: The slides show another version that has a method that repeats a given // character and number of times. This would help readability of your code. // (It looks very similar to the pseudocode that we wrote on Monday!) // We didn't however write this version in class. public class StarsFinalVersion { public static void main(String[] args) { printLine(13); printLine(7); printLine(35); printBox(10, 5); printBox(5, 6); } // Prints out a line of stars of the given length public static void printLine(int numberOfStars) { repeatText("*", numberOfStars); System.out.println(); } // Prints out a hollow box of stars of the given width and height public static void printBox(int width, int height) { printLine(width); for (int line = 1; line <= height - 2; line++) { System.out.print("*"); repeatText(" ", width - 2); System.out.println("*"); } printLine(width); } // Prints the given string "repeat" number of times, all on one line public static void repeatText(String text, int repeat) { for (int i = 1; i <= repeat; i++) { System.out.print(text); } } }