Practice-It! logo

Exercise 4.1: fractionSum

Added by: Will Beebe
Keywords: return

NOTE: This problem seems to come from an oudated edition of the Building Java Programs textbook. Please make sure that you are solving the problem from the right edition of the textbook that you are using in your class. (Click here to jump to the current edition's version of this problem instead.)

Write a method called fractionSum that accepts an integer parameter n and returns as a double the sum of the first n terms of the sequence:

fraction sum equation

In other words, the method should generate the following sequence:

1 + (1/2) + (1/3) + (1/4) + (1/5) + ...

You may assume that the parameter n is non-negative.

You must log in before you can solve this problem.

Log In

indent Re-indent

If you do not understand how to solve a problem or why your solution code doesn't work, please contact your TA or instructor.

If something seems wrong with the Practice-It system itself (errors, slow performance, incorrect problem descriptions/tests, etc.), please contact us.

Is there a problem?
Contact a Practice-It administrator.