// Rectangle.java - This program prints the outline of a rectangle with 10 asterisks // across and 12 asterisks down. // Input: None. // Output: Prints the outline of the rectangle. public class Rectangle { public static void main(String args[]) { int height = 10; // Number of asterisks to print across. must be greater than 1 int width = 12; // Number of asterisks to print down. must be greater than 1 int row; // Loop control for row number. int column; // Loop control for column number char outChar = '*'; // Character for outside of rect char inChar = ' '; // Character for inside of rectangle char fillChar; // Character for line fill for (row=0; row < height; row++) { if (row < height - 1 && row > 0 ) //first or last line? { fillChar = inChar; } System.out.println(this.buildLine(width, outChar, fillChar)); } System.exit(0); } // End of main() method. public static char[] buildLine( int width, char outChar, char fillChar) { char[] lineBuff[width] = fillChar; //I'm not sure if this is more or less expensive //than a bunch of individual writes... ? lineBuff[0] = outChar; lineBuff[width - 1] = outChar; return lineBuff; } } // End of Rectangle class.