programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Array Methods for Fabonacci Series

Daisy Smith
Greenhorn
Posts: 27
1
Hi.
I have written a program to output the nth Fibonacci number.(n is the number inputted) I used arrays to do that but now I want to know the highest Fibonacci number that my machine can display. What are and how do you use some of the arrays methods to do that? (I mean without first initializing the array).
I would really appreciate all the help I can get.

Junilu Lacar
Sheriff
Posts: 11494
180
You can find that information in JLS 10.7 (Array Members): http://docs.oracle.com/javase/specs/jls/se7/html/jls-10.html#jls-10.7

The highest Fibonacci number that the machine can display is not determined by anything pertaining to arrays. It is determined by the limits of the type of variable you use for the Fibonacci numbers themselves. If you are using an array of int, then the limit would be the maximum value for the primitive type int.

Junilu Lacar
Sheriff
Posts: 11494
180
BTW, it's not necessary to use an array to hold the numbers you calculate. Just use another variable to track how many Fibonacci numbers you've already found.

Campbell Ritchie
Marshal
Posts: 56600
172
If you use BigInteger, the limit depends more on how much memory you have and how long you have to read the output. There is a relationship between the place in the Fibonacci series and its value; it involves √5. You can find more about it in this Wikipedia article. You can work out what the largest Fibonacci number is, which will fit into a long (up to 9223372036854775807L).

Stuart A. Burkett
Ranch Hand
Posts: 679
But if you do want to keep a record of all the numbers in the sries, use an ArrayList instead of an array.