Yesterday I posted my code saying taht i coudnt get it to compile due to errors and such. So i took a break then came back to it after i thought about it somemore. Last night i got it to compile and for the most part it works. Although when I use input for the code everything works fine until i get to 5 on the fibonacci sequence.
The code Yields: If it's done correctly it should be like this:
Here is the code:
This is the JDialog.java Im using this code for input and output. This is how the professor wants it done just so everyone knows.
You need to think about what you're trying to do and then look at what you're actually doing. The reason you're getting 13 instead of 8 when you enter 5 is because your program prompts for indexes of the Fibonacci pattern and not the actually values in the pattern themselves.
Take a look at the Fibonacci pattern:
0 1 1 2 3 5 8 13
When n is 1 in your program, the sum is 2. What this means is that your starting index is the 2 of the pattern. When n is 2, it returns the 2nd index (one to the right of 2) which is 3. This part is deceiving because 3 is also the next value in the pattern after 2. But the input 2 is simply referring to the index. When you type is 3, the next value in the pattern, 5, is returned. Once again, 5 happens to be the Finbonacci number after 3, creating a confusing coincidence. When you type in 4, the next value 8 is returned. When you type in 5, the next value 13 is returned. It doesn't return 8 because although 8 comes after 5 in the pattern, the 5 is merely at index of the pattern, not a value in the pattern.
That may have been confusing to follow, but it comes down to this: What do you want your program to do? Is the input number a number from the Fibonacci sequence where the program's job is to find the next number in the pattern. -OR- Is the input number an index of the pattern where the program's job is to find the value at that index of the pattern?
Joined: Dec 05, 2012
Joel i just want to say i have posted my problem on about three sites I would like to let you know your the first person who has told me whats wrong. Thank you very much. To answer your question i need it to find the next number in the sequence when someone inputs one number. Like if someone put 5 in it should come back with 8.
The quieter you are, the more you are able to hear.
Joined: Dec 05, 2012
Sorry to offend you but this isnt the same as my post from before this is a different problem from before. I listened to what you told me about the comments and thats what got me here so thank you for that but i posted back on the post and no one was responding....So, I worked on it a little more and figured out what increment index was. This isn't the same problem that i asked in my last post it's similar but not the same.