Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Functions, real numbers and for loops

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Location
    California
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Functions, real numbers and for loops

    Hi, I have this Java problem and I don't completely understand what it means, this is the problem:

    Write a function named sumTo() that takes an integer parameter n and that returns the sum of the first n reciprocals. In other words:

    sumTo(n) returns (1 + 1/2 + 1/3 + 1/4 + ... + 1/n)


    (of course, 1/2 in this case means .5) For example, sumTo(2) should return the value 1.5 (1 + 1/2). If sumTo() is passed the value 0, it should return 0.0 as its result. You may assume that sumTo() is never passed a negative value.

    Thanks


  2. #2
    Member
    Join Date
    Jun 2011
    Posts
    56
    Thanks
    2
    Thanked 7 Times in 6 Posts

    Default Re: Functions, real numbers and for loops

    Learn how to use loops.
    Also note that
    1 + 1/2 + 1/3 + 1/4 + .... = 1/1 + 1/2 + 1/3 + ... = sum(1/i, for i = 1 to n)
    Your mission is to write the last expression in for loops which should be pretty easy.
    Last edited by dabdi; October 15th, 2011 at 07:14 AM.

Similar Threads

  1. Hash Functions
    By Blueshark in forum Java Theory & Questions
    Replies: 3
    Last Post: July 2nd, 2012, 03:04 PM
  2. Mapping real coordinates into GUI
    By gloor in forum AWT / Java Swing
    Replies: 2
    Last Post: May 26th, 2011, 08:35 AM
  3. Directing JButtons to functions?
    By scopolamine in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 10th, 2011, 11:22 AM
  4. Testing if dates are real or not.
    By cardsfan33 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 22nd, 2011, 07:46 PM
  5. Changing colors of large image in real time
    By chals in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: May 7th, 2009, 05:06 AM