Results 1 to 5 of 5
- 10-02-2011, 05:38 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 38
- Rep Power
- 0
Summing a Series: Is this correct??
Write a program to sum the following series:
(1/3) + (3/5) + (5/7) + (7/9) + (9/11) + (11/13) + ... + (95/97) + (97/99)
This is my attempt.
This is the output I get.Java Code:public class SummingSeries { public static void main(String[] args) { double sum = 0.0; for(double i = 1; i <= 99; i++) { sum += ((i+2)/(i+4)); } System.out.println("The sum is " + sum); } }
Is my output correct? I have no idea what the desired output is supposed to be so I need to know if 92.73308433232398 is actually the sum of the series mentioned above. Is there anything wrong with my code? I think my code is correct but I'm not sure.The sum is 92.73308433232398
- 10-02-2011, 06:48 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
- 10-02-2011, 08:09 PM #3
Member
- Join Date
- Oct 2010
- Posts
- 38
- Rep Power
- 0
Re: Summing a Series: Is this correct??
I see my mistake now thanks. I fixed my code.
Is my code correct now? or is there something else I need to fix?Java Code:public class SummingSeries { public static void main(String[] args) { double sum = 0.0; for(double i = 1; i <= 49; i++) { sum += ((2*i-1)/(2*i+1)); } System.out.println("The sum is " + sum); } }
- 10-02-2011, 08:36 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
- 10-05-2011, 05:36 PM #5
Member
- Join Date
- Oct 2010
- Posts
- 38
- Rep Power
- 0
Similar Threads
-
Summing the digit
By gozuhair in forum New To JavaReplies: 13Last Post: 07-18-2011, 07:09 AM -
summing value within Hashtable
By dc0m in forum New To JavaReplies: 4Last Post: 09-23-2010, 12:17 AM -
Perrin series
By moamen in forum New To JavaReplies: 6Last Post: 12-04-2009, 05:27 PM -
Help with summing series
By xplsivo in forum New To JavaReplies: 8Last Post: 11-23-2009, 07:37 PM -
How to add a second series in jfreechart
By Manfizy in forum New To JavaReplies: 1Last Post: 03-23-2009, 11:16 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks