Programming Exercises

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.

created 01/01/03


Chapter 71 Programming Exercises


Exercise 1

Write a program that implements this definition of square numbers:

square(1) = 1
square(N) = square(N-1) + 2N -1

Make a complete program similar to TriangleTester.java given in the chapter.

Aside: where did this crazy definition of square come from?

Easy: this is just algebra:

(N-1)2 = N2 - 2N + 1

rearrange to get:

 N2    = (N-1)2 + 2N - 1

Square numbers are also mentioned in the quiz for this chapter.

Click here to go back to the main menu.


End of Exercises