Method takes in the width of the desired right triangle, which must be a positive integer, then prints out a left aligned, right angled triangle, in which every row consists of repeating consecutive numbers starting at 1, and ending at the user specified width. Every time the method recurses, the width it takes in consecutively decreases, and prints out the current line, which is the previous method call with the addition of the current number. This enables the rows to start printing at 1, and with each recursion, adds the next integer to every row, resulting in a right angled triangle of increasing integers.
numberedTriangle(5)
=numberedTriangle(4) + "5"
=numberedTriangle(3) + "4" + "5"
=numberedTriangle(2) + "3" + "4" + "5"
=numberedTriangle(1) + "2" + "3" + "4" + "5"
=numberedTriangle(0) + "1" + "2" + "3" + "4" + "5"
= "" + "1"
="" + "1" + "2"
="" + "1" + "2" + "3"
="" + "1" + "2" + "3" + "4"
="" + "1" + "2" + "3" + "4" + "5"
Case 1: user inputs width of triangle as 12
Enter number of columns:
12
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10 11
1 2 3 4 5 6 7 8 9 10 11 12