Results 1 to 4 of 4

Thread: Help with Array

  1. #1
    artemusxi is offline Member
    Join Date
    Oct 2011
    Posts
    3
    Rep Power
    0

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

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

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

  3. #3
    artemusxi is offline Member
    Join Date
    Oct 2011
    Posts
    3
    Rep Power
    0

    Default Re: Help with Array

    Quote Originally Posted by pbrockway2 View Post
    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!

  4. #4
    artemusxi is offline Member
    Join Date
    Oct 2011
    Posts
    3
    Rep Power
    0

    Default Re: Help with Array

    Quote Originally Posted by pbrockway2 View Post
    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!

Similar Threads

  1. Replies: 0
    Last Post: 05-12-2011, 07:04 PM
  2. Replies: 23
    Last Post: 09-07-2010, 08:12 PM
  3. Replies: 2
    Last Post: 09-06-2010, 01:03 AM
  4. Convert Char Array to String Array
    By Mayur in forum New To Java
    Replies: 8
    Last Post: 10-12-2009, 11:41 AM
  5. Replies: 1
    Last Post: 03-31-2009, 06:40 AM

Posting Permissions

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