Write static methods that implement these recursive formulas to compute geometric( n) and harmonic(n). Do not forget to include a base case, which is not given in these formulas, but which you must determine. Place the methods in a test program that allows the user to compute both geometric(n) and harmonic(n) for an input integer n. Your program should allow the user to enter another value for n and repeat the calculation until signaling an end to the program. Neither of your methods should use a loop to multiply n numbers.

A geometric progression is defined as the product of the first n integers, and is denoted as
geometric(n) =
where this notation means to multiply the integers from 1 to n. A harmonic progression is defined as the product of the inverses of the first n integers, and is denoted as
harmonic(n) =
Both types of progression have an equivalent recursive definition:
geometric(n) =
harmonic(n) =

This is another easy program to write as a recursive algorithm. One little detail is to avoid integer division truncation when calculating the harmonic progression by casting the numerator (1) in the division to double. Also note that it is easy to enter a value that will cause either an overflow for the geometric progression calculation or underflow for the harmonic progression calculation. Students should be made aware of these common pitfalls, especially because the system does not flag them as errors.


See the code in GeometricAndHarmonicProgressions.java.

Computer Science & Information Technology

You might also like to view...

What is displayed after line 8 is run?

A. eggs B. milk C. cheese D. The program crashes.

Computer Science & Information Technology

Unlike other types of passwords which may be defeated using traditional password cracking software, CMOS passwords often require hardware manipulation on the part of the investigator

Indicate whether the statement is true or false.

Computer Science & Information Technology

You can insert or create mathematical equations using the Equation button in the Symbols group on the Insert tab.? ____________________

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

The bitwise ____ operator sets a bit to 1 only if one bit 1 and the other is 0.

A. and     B. exclusive or C. inclusive or D. complement

Computer Science & Information Technology