Formula for Triangle Numbers

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.

Answer:

Triangle Numbers
RowsTriangle(Rows) Formula
1 1 base case
2 3 2 + Triangle(1)
3 6 3 + Triangle(2)
4 10 4 + Triangle(3)
5 15 5 + Triangle(4)
6 21 6 + Triangle(5)
7 28 7 + Triangle(6)

Formula for Triangle Numbers

The table shows values of the Triangle() function. For example, Triangle(4) = 10. But it stops at seven. What is Triangle(12)?

We have figured out that the following is true:

total number of pins in N rows = number of pins in row N + 
                                 total number of pins in N-1 rows
                           
                               = N + total number of pins in N-1 rows

This can be written as a formula:

Triangle( N ) = N + Triangle( N - 1 )

So the number of pins in a 12 row arrangement is 12 + number of pins in 11 rows.

QUESTION 4:

How many pins are in 11 rows?