The purpose of this exercise is to train you to work with loop statements.
Estimated workload of this exercise is 30 min.
Please, proceed to LoopStatements class
and implement its static methods:
-
int sumOfFibonacciNumbers(int n)
For a positive integer n, calculate the result value, which is equal to the sum of the first n Fibonacci numbers. -
Note: Fibonacci numbers are a series of numbers in which each next number is equal to the sum of the two preceding ones: 0, 1, 1, 2, 3, 5, 8, 13... (the value of the fist element in Fibonacci numbers is "0", the values of the second and the third elements are equal to "1", for other elements use the formula F(n)=F(n-1)+F(n-2))
n = 8 -> result = 33
n = 11 -> result = 143
Code Sample:
...
System.out.println(LoopStatements.sumOfFibonacciNumbers(8));
System.out.println(LoopStatements.sumOfFibonacciNumbers(11));Output:
33
143