Iterative Triangle

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:

Of course.

Iterative Triangle

Here is an iterative method that calculates Triangle

int Triangle( int N )
{
  int totalPins = 0;
  for ( int row=1; row<=N; row++ )
    totalPins += row;
    
  return totalPins;
}

You might prefer it to the recursive version because the code looks familiar. But notice that it is not as clear that it implements the definition.

QUESTION 19:

Is there a formula that gives Triangle(N) immediately?