I'm immensely confusing myself trying to solve these problems. The reason why I'm doing this is because, I would like to polish and better my math skills.
Here is problem_2.
Quote
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.
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.
Here is my approach in java.
public static void main(String[] args)
{
int sum=0,prev1=2,prev2=4;
for(int i =0;prev1<4000000;i++){
System.out.print("SUM:"+sum+"\n");
sum= prev1+prev2; System.out.print("Previous: "+prev1+"\n");
prev1=prev2;
prev2=sum;
}
System.out.println("Result:"+ sum);
}


Sign In
Create Account


Back to top









