Difference between revisions of "Fibonacci sequence"

From CompSciWiki
Jump to: navigation, search
Line 4: Line 4:
  
 
|Problem=Write a complete Java program Fibonacci that:<br/>
 
|Problem=Write a complete Java program Fibonacci that:<br/>
*prompts the 10th fibonacci numbers using ''FOR'' loop(i.e. F(10))<br/>
+
*prompts the 10th fibonacci numbers using ''FOR'' loop (i.e. F(10))<br/>
 
*prints out the 10th fibonacci number, using System.out.println<br/>
 
*prints out the 10th fibonacci number, using System.out.println<br/>
 
<br/>
 
<br/>

Revision as of 22:38, 1 April 2010

Back to the Program-A-Day homepage

Problem

Write a complete Java program Fibonacci that:

  • prompts the 10th fibonacci numbers using FOR loop (i.e. F(10))
  • prints out the 10th fibonacci number, using System.out.println


Your output should look something like
"The 10th number of the fibonacci sequence is X". (where X should be the 10th number.)

Note that the fibonacci sequence is F(0) = 1, F(1) = 1, F(n) = F(n-1) + F(n-2) for n > 1.
Example: F(5) = 1, 1, 2, 3, 5

 

...by students

float
Taken from http://www.flickr.com/photos/daniello/565304023/

An image or By Students section

Solution

public class Fibonacci { public static void main(String[] args) { int answer = 0;

for(int n = 1; n < 11; n++) { if(n == 0

Code

Solution Code

Back to the Program-A-Day homepage