*
The moose likes Beginning Java and the fly likes Fibonacci numbers are 0 and 1. 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 numbers are 0 and 1." Watch "Fibonacci numbers are 0 and 1." New topic
Author

Fibonacci numbers are 0 and 1.

sudhakar venkat
Greenhorn

Joined: Apr 28, 2008
Posts: 8
How to slove this problem.

First 2 Fibonacci numbers are 0 and 1.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Hi,

i can not understand this!

thanks & regards,
seetharaman
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

How to slove this problem.

What is your problem ? If you know what a Fibonacci number is, you should not have any problem Where are you stuck ?


[My Blog]
All roads lead to JavaRanch
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

And yes dont expect us to do your homework, DoYourOwnHomework



Hope this helps


SCJP, SCWCD.
|Asking Good Questions|
abhishek pendkay
Ranch Hand

Joined: Jan 01, 2007
Posts: 184
seetharam
i can not understand this!

What is it that you cannot understand


The significant problems we face cannot be solved by the same level of thinking which created them – Einstein
SCJP 1.5, SCWCD, SCBCD in the making
Mintoo kumar
Ranch Hand

Joined: Aug 21, 2007
Posts: 61
if you want to know the code.

code:
________________________________________________________________

[solution deleted]
_________________________________________________________________

Might above code will be helpful and also change accordingly above is the basic exampel.

______________________________________________________________________
Mintoo
SCJP 1.4
_______________________________________________________________________
[ April 30, 2008: Message edited by: fred rosenberger ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
Originally posted by mintoo kumar:
if you want to know the code.
Please don't simply post answers like that, otherwise nobody will learn anything.

And the first two Fibonacci numbers in the commonest sequence are 1 and 1, not 0 and 1. The 10th number in the commonest fibonacci sequence is 55. Your method prints 55 as the 9th member of its sequence.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

And the first two Fibonacci numbers in the commonest sequence are 1 and 1, not 0 and 1.

Wikipedia does not agree
Mintoo kumar
Ranch Hand

Joined: Aug 21, 2007
Posts: 61
Dear Ritchie,

I do agree that i should not write simply the code ,actually i misunderstood the problem. But as far as my code is concernt it's fine

___________________________________________________________________________
And the first two Fibonacci numbers in the commonest sequence are 1 and 1, not 0 and 1. The 10th number in the commonest fibonacci sequence is 55. Your method prints 55 as the 9th member of its sequence.
___________________________________________________________________________

In my code i consider a=0,b=1 which is the initial number of fibnocii series. I have not mentioned it in output because i already declalred it .so if you consider this a=0,b=1 then output will be like 0,1,1,2,3.....
I believe now you will find it correct.

________________________________________________________________
Mintoo
________________________________________________________________
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11412
    
  16

Originally posted by mintoo kumar:
I do agree that i should not write simply the code

Mintoo

JavaRanch policy is that we do not provide solutions. I guess the corolary to Do Your Own Homework would be "Don't Do Someone Else's Homework". I have removed your solution.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
Originally posted by Christophe Verre:

Wikipedia does not agree
And how often has Wikipedia got anything right?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Originally posted by Campbell Ritchie:
And how often has Wikipedia got anything right?


Pretty often. I mean, I know that wikipeida is more than capable of getting things wrong, but overall my experience is that their info is good much more often than it's bad. You seem to be massively overstating their problems.

In this case, it seems obvious that the Fibonacci sequence F(1, 1) is a subsequence of F(0, 1). So are F(1, 2), F(2, 3), F(2, 5) etc. And there's no other Fibonacci sequence that F(0, 1) is contained within. So it seems natural to start the sequence as far back as possible and consider that the beginning. It's possible to define things differently, but I don't really see the point. The differences are pretty trivial anyway, as long as you know which definition is being used at any given time.


"I'm not back." - Bill Harding, Twister
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
All right, then, I'll believe that the 0th member is 0 and the 1st member is 1, at least of the commonest Fibonacci sequence. That has the advantage of allowing you to say
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Um, OK. The Wikipedia article also uses 0 and 1 as the indices for values 0 and 1. It's arguable whether those should be called "first" and "second" or "zeroth" and "first". But we have that same ambiguity talking about Java arrays.

[Jim]: And there's no other Fibonacci sequence that F(0, 1) is contained within.

This is an error on my part. The main Fibonacci sequence can be extended as far back as you like. E.g.

F(13, -8) = 13, -8, 5, -3, 2, -1, 1, 0, 1, 1, 2, 3, 5, 8, 13...

which contains F(0, 1) within it, starting from position 7 (the eighth element) . Note that the magnitudes of the earlier values mirror the later values, with alternating sign. It still seems to make some sense to me to choose 0 as the main reference point, due to symmetry. But it isn't really the earliest point possible; there is no earliest point possible.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Fibonacci numbers are 0 and 1.