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. ## fibonnaci

I'm trying to calculate the following problem stuck at the moment, I don't want the answer rather would greatly appreciate if anyone could guide me to some resources which may help. I understand the problem just not sure how to represent it.

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

I'm stuck on the part about the sum of even value terms. The following is my latest attempt which I know is wrong.
```public class main{
public static void main(String[] args){

for(int i = 0;i<=33;i++){
if(i%2==0){

System.out.print(fibonnaci(i) + " ");
}
}
}
static int fibonnaci(int n){
if(n==0){
return 0;
}else if(n==1){
return 1;
}else{
return fibonnaci(n-1)+ fibonnaci(n-2);
}

}
}```
Thank you to the mod who advised me to check out project Euler, even though I'm rubbish at solving the problems, it's still great.

3. ## Re: fibonnaci

You're too quick here. Break it up into little pieces. First try to gernerate the fibonacci series up to four million. When you've done that, think about how you add up the even vlues. Right now you're checkin whether the index of the sequence is even. I understand it that you have to add 2+8+34 and so on.

4. ## The Following User Says Thank You to PhHein For This Useful Post:

keepStriving (May 14th, 2013)

5. ## Re: fibonnaci

Thank you for helping, I'll try again.

6. ## Re: fibonnaci

I've solved the question, I need to spend more time contemplating what the question is asking next time.

7. ## Re: fibonnaci

Originally Posted by keepStriving
I've solved the question...