Java Fibonacci number generator

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gerbi7
    FFR Player
    • Feb 2006
    • 276

    #1

    Java Fibonacci number generator

    1 1
    2 1
    3 2
    4 3
    5 5
    6 8
    7 13
    8 21
    9 34
    10 55
    11 89
    12 144
    13 233
    14 377
    15 610
    16 987
    17 1597
    18 2584
    19 4181
    20 6765
    21 10946
    22 17711
    23 28657
    24 46368
    25 75025
    26 121393
    27 196418
    28 317811
    29 514229
    30 832040
    31 1346269
    32 2178309
    33 3524578
    34 5702887
    35 9227465
    36 14930352
    37 24157817
    38 39088169
    39 63245986
    40 102334155
    41 165580141
    42 267914296
    43 433494437
    44 701408733
    45 1134903170
    46 1836311903

    47 -1323752223

    Java can't store more than 10 digits.

    If anyone knows any kind of crazy random way to fix this, it would be greatly accepted.
    Squirrels are evil.
  • JKPolk
    tool
    • Aug 2003
    • 3737

    #2
    Re: Java Fibonacci number generator

    use long data types
    they go heap big number

    Comment

    • gerbi7
      FFR Player
      • Feb 2006
      • 276

      #3
      Re: Java Fibonacci number generator

      long?

      Works as a variable type.

      -Tests with long instead of int

      Woot. Works better now.

      -Tries up to 100

      Screws up on 93, 19 digits. Helped, but didn't fix.

      1 1
      2 1
      3 2
      4 3
      5 5
      6 8
      7 13
      8 21
      9 34
      10 55
      11 89
      12 144
      13 233
      14 377
      15 610
      16 987
      17 1597
      18 2584
      19 4181
      20 6765
      21 10946
      22 17711
      23 28657
      24 46368
      25 75025
      26 121393
      27 196418
      28 317811
      29 514229
      30 832040
      31 1346269
      32 2178309
      33 3524578
      34 5702887
      35 9227465
      36 14930352
      37 24157817
      38 39088169
      39 63245986
      40 102334155
      41 165580141
      42 267914296
      43 433494437
      44 701408733
      45 1134903170
      46 1836311903
      47 2971215073
      48 4807526976
      49 7778742049
      50 12586269025
      51 20365011074
      52 32951280099
      53 53316291173
      54 86267571272
      55 139583862445
      56 225851433717
      57 365435296162
      58 591286729879
      59 956722026041
      60 1548008755920
      61 2504730781961
      62 4052739537881
      63 6557470319842
      64 10610209857723
      65 17167680177565
      66 27777890035288
      67 44945570212853
      68 72723460248141
      69 117669030460994
      70 190392490709135
      71 308061521170129
      72 498454011879264
      73 806515533049393
      74 1304969544928657
      75 2111485077978050
      76 3416454622906707
      77 5527939700884757
      78 8944394323791464
      79 14472334024676221
      80 23416728348467685
      81 37889062373143906
      82 61305790721611591
      83 99194853094755497
      84 160500643816367088
      85 259695496911122585
      86 420196140727489673
      87 679891637638612258
      88 1100087778366101931
      89 1779979416004714189
      90 2880067194370816120
      91 4660046610375530309
      92 7540113804746346429


      93 -6246583658587674878
      94 1293530146158671551
      95 -4953053512429003327
      96 -3659523366270331776
      97 -8612576878699335103
      98 6174643828739884737
      99 -2437933049959450366
      100 3736710778780434371
      Squirrels are evil.

      Comment

      • Afrobean
        Admiral in the Red Army
        • Dec 2003
        • 13262

        #4
        Re: Java Fibonacci number generator

        Can Java use Double Long?

        Comment

        • JKPolk
          tool
          • Aug 2003
          • 3737

          #5
          Re: Java Fibonacci number generator

          as far as i've seen, no

          if you really wanted to be tricky, you could break up the number into a char array, then recursively add each column of characters.

          that'd work for numbers as large as the biggest contiguous stack of memory in your pc

          Comment

          • gerbi7
            FFR Player
            • Feb 2006
            • 276

            #6
            Re: Java Fibonacci number generator

            Yeah. I was thinking something like that, but how the heck are you going to do that. >_>

            -Thinks hard.

            So, make a loop that will add each caracter, and if it's greater than ten, make the digit to the left increase by one, and then subract ten from the addition, and make that the new caracter for the digit added.
            Squirrels are evil.

            Comment

            • JKPolk
              tool
              • Aug 2003
              • 3737

              #7
              Re: Java Fibonacci number generator

              it's not that hard, it's just a messy initial thought to form
              i'm sure once you have a prototype running you can find some places to optimize code

              Comment

              • gerbi7
                FFR Player
                • Feb 2006
                • 276

                #8
                Re: Java Fibonacci number generator

                I never really learned too much about arrays, so this is going to be a little bit of a challenge.

                I'll fool around and see what I can come up with.
                Squirrels are evil.

                Comment

                • JKPolk
                  tool
                  • Aug 2003
                  • 3737

                  #9
                  Re: Java Fibonacci number generator

                  If you have questions, feel free to ask.

                  Comment

                  • Tasselfoot
                    Retired BOSS
                    FFR Simfile Author
                    • Jul 2003
                    • 25185

                    #10
                    Re: Java Fibonacci number generator

                    what is the assignment? like... why do you need to code fibonacci greater than the 92nd in the sequence?

                    and, have you tried googling or going to a java-specific forum for help?
                    RIP

                    Comment

                    • JKPolk
                      tool
                      • Aug 2003
                      • 3737

                      #11
                      Re: Java Fibonacci number generator

                      It's not for anything school related. He got tired of having to manually do things in the Fibonacci thread and decreed that he would write a program to do everything for him.
                      This is that program, and it's turning out to be a bit more complicated than he'd anticipated due to the nature of Java's variable lengths.

                      Comment

                      • gerbi7
                        FFR Player
                        • Feb 2006
                        • 276

                        #12
                        Re: Java Fibonacci number generator

                        I used to have a java help site, but I lost the url for it.

                        Googling didn't help much for me either.


                        JKPolk nailed why I'm doing this.
                        Squirrels are evil.

                        Comment

                        • Squeek
                          let it snow~
                          • Jan 2004
                          • 14444

                          #13
                          Re: Java Fibonacci number generator



                          If that doesn't help, make the number instead an array of bytes. Work with it that way. It sucks to do it, but you can have a number with an infinite size.

                          ~Squeek

                          Comment

                          • Tasselfoot
                            Retired BOSS
                            FFR Simfile Author
                            • Jul 2003
                            • 25185

                            #14
                            Re: Java Fibonacci number generator

                            oh yea. I forgot about the BigInteger class. Meh... I've even used it before too.
                            RIP

                            Comment

                            • gerbi7
                              FFR Player
                              • Feb 2006
                              • 276

                              #15
                              Re: Java Fibonacci number generator

                              I don't see how I'm going to print out the numbers though.

                              Making my own array would probably be better anyways. I could use with figuring out how to use it.
                              Squirrels are evil.

                              Comment

                              Working...