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.

Click here view the solution for this question


End of Exercises