Skip to content

nelthecoder/fibonacci

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sum of Fibonacci numbers.

The purpose of this exercise is to train you to work with loop statements.

Estimated workload of this exercise is 30 min.

Description

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))

Example:

n = 8 -> result = 33
n = 11 -> result = 143


Examples


Code Sample:

...
System.out.println(LoopStatements.sumOfFibonacciNumbers(8));
System.out.println(LoopStatements.sumOfFibonacciNumbers(11));

Output:

33
143

About

Java Exercise Solution

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages