// CSE 142, Summer 2008 (Marty Stepp) // This program draws lines and boxes of stars of various sizes. public class Stars { public static void main(String[] args) { drawLineOfStars(13); drawLineOfStars(7); drawLineOfStars(35); System.out.println(); drawBox(10, 3); drawBox(5, 4); drawBox(10, 6); // draw many boxes of different sizes for (int i = 4; i <= 10; i++) { drawBox(i, i); } } // Draws a line of stars of 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 of the given width and height. public static void drawBox(int width, int height) { drawLineOfStars(width); // top // middle for (int line = 1; line <= (height - 2); line++) { System.out.print("*"); for (int space = 1; space <= (width - 2); space++) { System.out.print(" "); } System.out.println("*"); } drawLineOfStars(width); // bottom } }