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 3 of 3

Thread: displaying sum of harmonic series

  1. #1
    Junior Member
    Join Date
    Jun 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default displaying sum of harmonic series

    Hai Team

    i am new to Java programming language.i want to write a program on printing the sum of harmonic

    series for a given value of 'n' 1+1/2+1/3.......1/n

    please do help me on this issue along with the code

    Thanks in Advance

    kundan



  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: displaying sum of harmonic series

    public double sumHarm(int n){
         int total = 0;
         for(int i = 1; i <= n; i++) total += (1.0/i);
         return total;
    }

    Something like that should do it.

    Regards,
    Chris

  3. #3
    Junior Member
    Join Date
    Jun 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: displaying sum of harmonic series

    Hi Chris

    Thanks alot it worked out for me
    thank you very much
    have a great day


Similar Threads

  1. Creating and displaying a JPanel inside another JPanel
    By JayDuck in forum AWT / Java Swing
    Replies: 1
    Last Post: April 7th, 2009, 08:02 AM