Pyramidal 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:

Three or four.

Pyramidal Numbers

Pyramid of tennis balls

Let us use three-sided pyramids (sometimes called tetrahedrons). To make the pyramid, start with a triangular arrangement of tennis balls for the bottom layer. Next stack up tennis balls layer at a time, as at right.

If the base of the pyramid has 5 balls along a side, how many balls does the entire pyramid have in it? Let us call this a pyramidal number.

Here is a chart that shows the number of balls in the side of a base, N, and the corresponding pyramidal numbers.

N1234567
Pyramid(N)1

The picture starts with the base of the pyramid for Pyramid(5). Click a few times to see the complete pyramid. Smaller pyramids can be found within this one. For small pyramids, count the balls within them. For larger pyramids, try to find a clever way to calculate the number of balls.

QUESTION 2:

Click on the image a few times and fill in some of the chart.