Daisy Smith

Greenhorn

Posts: 27

1

posted 4 years ago

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.

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.

posted 4 years ago

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.

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.

*Practice only makes habit, only perfect practice makes perfect.
Practice mindfully by doing the right things and doing things right.*— Junilu

[How to Ask Questions] [How to Answer Questions]

posted 4 years ago

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.

*Practice only makes habit, only perfect practice makes perfect.
Practice mindfully by doing the right things and doing things right.*— Junilu

[How to Ask Questions] [How to Answer Questions]

Campbell Ritchie

Marshal

Posts: 56600

172

posted 4 years ago

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