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

1. ## Sum of Factorials

Hi, I'm working on this code right now. The first method returns the factorial of an integer (factorial of 3 = 1x2x3). And the second returns the sum of the factorials between 2 integers. This is correct according to my professor. I'm just confused as to why in the 2nd methods it isn't "total = total + Factorial(i);" instead of what I have.

thanks for the help.

```public class LoopProblems
{
public int Factorial (int n){

int total = 1;

for (int i = 1; i <= n ; i++ ) {

total = total * i;
}

}

public int SumOfFactorials (int start, int end) {

int total = 1;

for (int i = start; i <= end ; i++ ) {

total = total * Factorial(i);
}

}
}```

2. ## Re: Sum of Factorials

What is the output from when the posted code is executed?
x * 0 = 0

3. ## Re: Sum of Factorials

So I changed it to 1. Is the code correct now?

Thanks!

4. ## Re: Sum of Factorials

Is the code correct now?
Hard to tell without testing it.
What happens when you compile and execute it?

5. ## Re: Sum of Factorials

I'm not quite sure how to do that yet. We're not quite there yet in class. I'm going to teach myself how to do that soon. We just kind of work it out logically. To me , it should be
`total = total + Factorial(i);`
Thanks!