// CSE 142, Autumn 2009, Marty Stepp // This program prints several lines and boxes of stars using parameters. // This is a second version of the program that parameterizes Strings. public class Stars2 { public static void main(String[] args) { lineOfCharacters("*", 13); System.out.println(); lineOfCharacters("*", 7); System.out.println(); lineOfCharacters("*", 35); System.out.println(); System.out.println(); boxOfStars(".", 10, 6); boxOfStars(" ", 5, 4); boxOfStars("x", 75, 27); } // Prints the given string repeated the given number of times. public static void lineOfCharacters(String letter, int times) { for (int i = 1; i <= times; i++) { System.out.print(letter); } } // Prints a box of stars of the given width and height, // with the given character as its "filling." public static void boxOfStars(String filling, int width, int height) { // top lineOfCharacters("*", width); System.out.println(); // middle of 10x6 box for (int line = 1; line <= (height - 2); line++) { System.out.print("*"); lineOfCharacters(filling, (width - 2)); System.out.println("*"); } // bottom lineOfCharacters("*", width); System.out.println(); } }