What's Here?
- Members: 118,478
- Replies: 434,471
- Topics: 67,155
- Snippets: 2,407
- Tutorials: 638
- Total Online: 955
- Members: 52
- Guests: 903
Who's Online?
|
Welcome to Dream.In.Code |
|
Getting Java Help is Easy!
Join 118,478 Java Programmers for FREE! Ask your question and get quick answers from experts. There are 955 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!
|
Outputs the fibonacci sequence using arrays very easy to change and alter to output more or less fibonacci numbers, can also be output to a txt file.
|
Submitted By: pink_floyd
|
|
Rating:

|
|
Views: 9,604 |
Language: Java
|
|
Last Modified: August 14, 2006 |
Snippet
//Programmed By: pink_floyd
//Date 08/08/06
//Fibonacci Sequence
import java.io.*;
public class FIBONACCI
{
{
int[] f = new int[46]; //creates array length of 46
f[0] = 1; //first item in array (computer starts counting at 0 not 1)
f[1] = 1; //second item in array
int x; //declares x of type int (integer)
System. out. print(f [0] + "\n" + f [1] + "\n"); //outputs the first 2 elements in array f
for(x=2; x<=45; x++) //notice 'x<=45' not 46 has to be 45 if any higher cannot handle array
{
f[x] = f[x-1] + f[x-2];//calculates next element in array
System. out. println(f [x ]); //output next elements in array 2-45
}
}
}
Copy & Paste
|
|
|
Reference Sheets
Bye Bye Ads
Free DIC T-Shirt
Related Sites
Monthly Drawing
Partners
Top Contributors
Top 10 Kudos This Month
|