package xmp_recurse;

public class Triangle {
	private int width;
	
	public Triangle(int width) {
		this.width=width;
	}
	
	public void draw() {
		if (width==0) return;
		// For width at top triangles, uncomment this code, and comment the invocation
		// below the recursive call...
		// String line="";
		// for(int i=0; i<width; i++) line += "[]";
		// System.out.println(line);
		if (width>1) {
			Triangle smaller=new Triangle(width-1);
			smaller.draw();
		}
		String line="";
		for(int i=0; i<width; i++) line += "[]";
		System.out.println(line);
		
	}
	
	public int tnum() {
		if (width==0) return 0;
		if (width==1) return 1;
		int ans=(new Triangle(width-1)).tnum();
		return ans+width;
	}
	
	

	public static void main(String[] args) {
		Triangle t = new Triangle(10);
		t.draw();
		System.out.println("Triangle number is: " + t.tnum());

	}

}
