Tech Support Guy banner
Status
Not open for further replies.

Java sequence generator

6K views 2 replies 2 participants last post by  Boe 
#1 ·
Hello everyone. I am not trying to get someone to do my homework for me but I am stuck on a program. I dont know if you are familiar with the "fibonacci generator". The first two nubers of the sequence are 1. The third number it always the sum of the prior two numbers. the third number is the sum of 1 and 1. third number = 2. the fourth number is the some of the 2nd and 3rd digit. the seguence reads as follows... 1,1,2,3,5,8,13,21.... so on. anyways, I need to write a generator to figure out this sequence so when a user enters a digit number, like the 16 fib number, then generator will tell the user what the actual number is.
 
#2 ·
Hi Boe,


// Fibonacci generator
// fill an array of 500 fibonacci numbers
//
int a[] = new int[500];
a[0] = 1;
a[1] = 1;
for (int i = 2; i < 500; i++)
{
a = a[i-1] + a[i-2];
}

// Display the Fibonacci number

int userValue = value entered by the user

System.out.println("Fibonacci number " + userValue + " = " + a[userValue - 1]);
 
Status
Not open for further replies.
You have insufficient privileges to reply here.
Top