• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array Methods for Fabonacci Series  RSS feed

 
Daisy Smith
Greenhorn
Posts: 27
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But if you do want to keep a record of all the numbers in the sries, use an ArrayList instead of an array.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!