A common example of a recursive formula is one to compute the sum of the first n integers, 1 + 2 + 3 + … + n. The recursive formula can be expressed as 1+2+3+…+n=n+(1+2+3+…+(n – 1)) Write a static method that implements this recursive formula to compute the sum of the first n integers. Place the method in a test program that allows the user to enter the values of n until signaling an end to execution. Your method definition should not use a loop to add the first n integers.

This Project is also very easy to write as a recursive algorithm. The base case returns one and any other case adds the number passed to it to the number returned by a recursive call with the number passed to it reduced by one. Note that the program loops until the user enters a positive integer since the progression is defined only for positive integers.


See the code in ArithmeticProgression.java.

Computer Science & Information Technology

You might also like to view...

The embossed media type is intended for paged material and for documents viewed in print preview mode.

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

Computer Science & Information Technology

Most coding errors are the result of improper capitalization or missing ____.

A. commands B. concatenation C. punctuation D. Either a or b

Computer Science & Information Technology

Conditional statements use ________________, such as = =, which is used to test for equality.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

A(n) ________ query is similar to a make table query, except that a query dataset is appended to an existing table

Fill in the blank(s) with correct word

Computer Science & Information Technology