• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

fibonacci program

 
Jessie Brown
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a program that i need to complete. I wrote the first one (FibonacciGenerator) with stated variables - everything worked fine
I now want to split it up so that the user can give a number and the program gives the correct number back. (ie, fib(5)=5 AND NOT fib(5)=2)
Please help as I know what i need to do but the how escapes me.

constructor portion


Test Program (I know i need to return the input to the constructor file but how??)


Any help is appreciated

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34214
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jessie,
Welcome to JavaRanch!

I don't really understand what you are asking. Your test program looks like it outputs the right number. Are you saying you want to move that logic to the Fibonacci class itself?
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your Fibonacci class works, if you ignore the element 0. I've changed your test program a bit:
Output:
You'll need to check the logic of your tester. You skip nextNumber for 1 and 2, so it skips the calculation of fib(1) and fib(2).
 
anandhi mohan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this code:



your n value should be starting from 1.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic