// CSE 142 Autumn 2007, Marty Stepp // // This program prints many lines and boxes of stars. // This version uses parameters to remove redundancy. // public class Stars2 { public static void main(String[] args) { drawLineOfStars(13); drawLineOfStars(7); drawLineOfStars(35); drawBox(5, 4); drawBox(10, 6); } // Draws a line of stars with the given length. public static void drawLineOfStars(int stars) { for (int i = 1; i <= stars; i++) { System.out.print("*"); } System.out.println(); } // Draws a box of stars with the given dimensions. public static void drawBox(int width, int height) { // top drawLineOfStars(width); // middle for (int line = 1; line <= height - 2; line++) { System.out.print("*"); for (int j = 1; j <= width - 2; j++) { System.out.print(" "); } System.out.println("*"); } // bottom drawLineOfStars(width); } }