This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "fibonacci program" Watch "fibonacci program" New topic

fibonacci program

Jessie Brown

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

Joined: May 26, 2003
Posts: 32633

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?

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Rob Spoor

Joined: Oct 27, 2005
Posts: 20132

Your Fibonacci class works, if you ignore the element 0. I've changed your test program a bit:
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).

How To Ask Questions How To Answer Questions
anandhi mohan

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

your n value should be starting from 1.
I agree. Here's the link:
subject: fibonacci program
It's not a secret anymore!