# Thread: Summing a Series: Is this correct??

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.
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);
}
}```
This is the output I get.
The sum is 92.73308433232398
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.  Reply With Quote

2. ## Re: Summing a Series: Is this correct?? Originally Posted by son012189 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.
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);
}
}```
This is the output I get.

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.
Take a few examples for 'i', say 1, 2 and 3 and see if you get the correct terms: 3/5, 4/6, 5/7; what is that 4/6 doing there?

kind regards,

Jos  Reply With Quote

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.

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);
}
}```
Is my code correct now? or is there something else I need to fix?  Reply With Quote

4. ## Re: Summing a Series: Is this correct?? Originally Posted by son012189 I see my mistake now thanks. I fixed my code.

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);
}
}```
Is my code correct now? or is there something else I need to fix?
It's fine now; you also could've done this:

Java Code:
```for (double i= 1; i <= 97; i+= 2)
sum+= i/(i+2);```
kind regards,

Jos  Reply With Quote

5. Member Join Date
Oct 2010
Posts
38
Rep Power
0

## Re: Summing a Series: Is this correct??

I see. Thanks.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•