What's Here?
- Members: 148,784
- Replies: 504,902
- Topics: 79,513
- Snippets: 2,661
- Tutorials: 705
- Total Online: 2,050
- Members: 82
- Guests: 1,968
|
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: 11,691 |
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
|
|
|
Be Social
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|