Moin Leute,
ich hab mal im Internet ne kleine Aufgabe gelesen und komm mal wieder nicht weiter.
aufgabe:
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.
Mein array1 gibt schon die richtigen zahlen aus:
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368
75025
121393
196418
317811
514229
832040
1346269
2178309
3524578
summe:9227463 (plus 1, da ich oben mit i=2 anfange)
aber wenn ich auf der Plattform die Lösung eingebe sagt er dass ich die falsche Lösung habe,
habe ich die Aufgabe richtig gemacht? oder ist nur ein leichtsinnsfehler drin?
Danke
ich hab mal im Internet ne kleine Aufgabe gelesen und komm mal wieder nicht weiter.
aufgabe:
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.
Java:
public class main2 {
public static void main(String [] args){
int[] array1 = new int[1000000];
int i=0;
int sum=0;
array1[1]=1;
array1[2]=2;
for(i=2; i<33; i++ ){
array1[i+1]=array1[i]+array1[i-1];
System.out.println(array1[i]);
}
for(i=0; i<33; i++){
sum += array1[i];
}
System.out.println("summe:"+sum);
}
}
Mein array1 gibt schon die richtigen zahlen aus:
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368
75025
121393
196418
317811
514229
832040
1346269
2178309
3524578
summe:9227463 (plus 1, da ich oben mit i=2 anfange)
aber wenn ich auf der Plattform die Lösung eingebe sagt er dass ich die falsche Lösung habe,
habe ich die Aufgabe richtig gemacht? oder ist nur ein leichtsinnsfehler drin?
Danke