01: /**
02:    This class describes triangle objects that can be displayed
03:    as shapes like this:
04:    []
05:    [][]
06:    [][][]
07: */
08: public class Triangle
09: {
10:    /**
11:       Constructs a triangle.
12:       @param aWidth the number of [] in the last row of the triangle.
13:    */
14:    public Triangle(int aWidth)
15:    {
16:       width = aWidth;
17:    }
18: 
19:    /**
20:       Computes a string representing the triangle.
21:       @return a string consisting of [] and newline characters
22:    */
23:    public String toString()
24:    {
25:       String r = "";
26:       for (int i = 1; i <= width; i++)
27:       {  
28:          // Make triangle row
29:          for (int j = 1; j <= i; j++)
30:             r = r + "[]";
31:          r = r + "\n";
32:       }
33:       return r;
34:    }
35: 
36:    private int width;
37: }