logo CodeStepByStep logo

fractionSum

Language/Type: Java for loops method basics return

Write a method named 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.

Method: Write a Java method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.