aspose file tools*
The moose likes Beginning Java and the fly likes fibonacci program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "fibonacci program" Watch "fibonacci program" New topic
Author

fibonacci program

Jessie Brown
Greenhorn

Joined: Jun 19, 2009
Posts: 1
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

Joined: May 26, 2003
Posts: 30764
    
156

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?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19722
    
  20

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).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
anandhi mohan
Greenhorn

Joined: Mar 24, 2009
Posts: 9
try this code:



your n value should be starting from 1.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: fibonacci program