// Helene Martin, CSE 142 // Displays patterns of stairs using loops import java.awt.*; public class Stairs { public static void main(String[] args) { DrawingPanel p = new DrawingPanel(160, 160); Graphics g = p.getGraphics(); stairs1(g); } // ten stacked rectangles starting at (20, 20), height 10, // width starting at 100 and decreasing by 10 each time public static void stairs1(Graphics g) { for (int i = 0; i < 10; i++) { g.drawRect(20, 20 + 10 * i, 100 - 10 * i, 10); } } // ten stacked rectangles starting at (20, 20), height 10, // width starting at 100 and decreasing by 10 each time // each rectangle starting 10pixels right of the last public static void stairs2(Graphics g) { for (int i = 0; i < 10; i++) { g.drawRect(20 + 10 * i, 20 + 10 * i, 100 - 10 * i, 10); } } /* The topmost rectangle is 10 wide. The bottom one starts at (20, 20) and is 100 wide. The rightmost point of the bottom rectangle is 100 + 20 = 120 The leftmost point of the top rectangle is 120 - 10 = 110 line starting x 110 + (i * -10) 0 110 1 100 2 90 */ public static void stairs3(Graphics g) { for (int i = 0; i < 10; i++) { g.drawRect(110 + (i * -10), 20 + 10 * i, 10 + 10 * i, 10); } } }