1. Member Join Date
Oct 2011
Posts
3
Rep Power
0

## Help with Array

I'm working on a project in my Java 2 course. I have the first two parts down but the final part has me stumped. I seriously think I am just over thinking this.

I am being asked to create a class that handles large array values (we have created a class that generates fibonacci numbers and stores them in an array) for example the 100th fibonacci number generated and stored in the array is
354,224,848,179,261,915,075 and represent it by four array elements:
- arrF[n] = 261915075
- arrF[n+1] = 224848179
- arrF[n+2] = 354
- arrF[n+3] = 0

and do the same for any other large number generated respectively.
I am not looking for an answer as I want to figure this out myself but any suggestions or hints to help put me on the right track would be apprectiated because as of now I am completely stumped! Thanks in advance for any assistance.  Reply With Quote

2. Moderator   Join Date
Feb 2009
Location
New Zealand
Posts
4,716
Rep Power
18

## Re: Help with Array

I'm not completely clear what you are asking. Have you already written the class that generates these Fib values as 4 part array values? Or does your existing code use some other data type?

-----

If you use BigInteger to generate the fibonacci sequence with f(n+1)=f(n)+f(n-1) then the four array elements can be obtained by dividing the Fib value by the appropriate powers of 10.

On the other hand you could create arrF directly by calculating the next four values based on the previous eight. The important step would be to figure out how to add two integer values like:

Java Code:
```a*10^0 + b*10^10 + c*10^20 + d*10^30
c*10^0 + d*10^10 + e*10^20 + f*10^30```
The sum will have "components" a+c, b+d, etc. But you have to be careful because, eg, a+c might be >= 10^10. You would have to check for that and possibly "carry" a 1 which would be added to b+d.  Reply With Quote

3. Member Join Date
Oct 2011
Posts
3
Rep Power
0

## Re: Help with Array Originally Posted by pbrockway2 I'm not completely clear what you are asking. Have you already written the class that generates these Fib values as 4 part array values? Or does your existing code use some other data type?

-----

If you use BigInteger to generate the fibonacci sequence with f(n+1)=f(n)+f(n-1) then the four array elements can be obtained by dividing the Fib value by the appropriate powers of 10.

On the other hand you could create arrF directly by calculating the next four values based on the previous eight. The important step would be to figure out how to add two integer values like:

Java Code:
```a*10^0 + b*10^10 + c*10^20 + d*10^30
c*10^0 + d*10^10 + e*10^20 + f*10^30```
The sum will have "components" a+c, b+d, etc. But you have to be careful because, eg, a+c might be >= 10^10. You would have to check for that and possibly "carry" a 1 which would be added to b+d.
Yes, I have written the class that generates the fibonacci numbers. In this case I am writing a second class (FibonacciLarge) that will simply utilize the code from my original class to generate the numbers. We limited the first class to the first 25 fib numbers. This time we will accept values up to f100 then take the 100th fib # and divide it up into 4 seperate array elements.

Thanks for the assistance!  Reply With Quote

4. Member Join Date
Oct 2011
Posts
3
Rep Power
0

## Re: Help with Array Originally Posted by pbrockway2 I'm not completely clear what you are asking. Have you already written the class that generates these Fib values as 4 part array values? Or does your existing code use some other data type?

-----

If you use BigInteger to generate the fibonacci sequence with f(n+1)=f(n)+f(n-1) then the four array elements can be obtained by dividing the Fib value by the appropriate powers of 10.

On the other hand you could create arrF directly by calculating the next four values based on the previous eight. The important step would be to figure out how to add two integer values like:

Java Code:
```a*10^0 + b*10^10 + c*10^20 + d*10^30
c*10^0 + d*10^10 + e*10^20 + f*10^30```
The sum will have "components" a+c, b+d, etc. But you have to be careful because, eg, a+c might be >= 10^10. You would have to check for that and possibly "carry" a 1 which would be added to b+d.
Yes, I have written the class that generates the fibonacci numbers. In this case I am writing a second class (FibonacciLarge) that will simply utilize the code from my original class to generate the numbers. We limited the first class to the first 25 fib numbers. This time we will accept values up to f100 then take the 100th fib # and divide it up into 4 seperate array elements.

Thanks for the assistance!  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•