Java Fibonacci number generator

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Squeek
    let it snow~
    • Jan 2004
    • 14444

    #16
    Re: Java Fibonacci number generator

    Originally posted by gerbi7
    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.
    It's an object.

    A simple toString() should do it.

    Then print out the string.



    toString

    public String toString()

    Returns the decimal String representation of this BigInteger. The digit-to-character mapping provided by Character.forDigit is used, and a minus sign is prepended if appropriate. (This representation is compatible with the (String) constructor, and allows for String concatenation with Java's + operator.)

    Overrides:
    toString in class Object

    Returns:
    decimal String representation of this BigInteger.
    See Also:
    Character.forDigit(int, int), BigInteger(java.lang.String)
    ~Squeek

    Comment

    • JKPolk
      tool
      • Aug 2003
      • 3737

      #17
      Re: Java Fibonacci number generator

      Man BigInteger is sweet... I should go play around on the API more often. There are so many cool things on there that make Java life even simpler than it already is.
      I've already handed in entire projects that were done using built-in classes, saving mountains of code. Teachers were pissed.

      Comment

      • gerbi7
        FFR Player
        • Feb 2006
        • 276

        #18
        Re: Java Fibonacci number generator

        Yeah, that's nice, but I never actually figured out how to use classes either. >_>

        I did get the array thing to work to print a number, except it's backwards.
        Squirrels are evil.

        Comment

        • JKPolk
          tool
          • Aug 2003
          • 3737

          #19
          Re: Java Fibonacci number generator

          Are you using a for() counter to print out the array?
          just do:
          Code:
          for(int i = ([I]arrayname[/I].length - 1); i >= 0; i--)
              System.out.print([I]arrayname[/I][i]);

          Comment

          • T0rajir0u
            FFR Player
            FFR Simfile Author
            • Aug 2005
            • 2946

            #20
            Re: Java Fibonacci number generator

            If you're using an array of ints you're majorly wasting space since you can use an array of bytes instead.

            But BigInteger is by far the easiest way to do what you want to do. Case closed.
            hehe

            Comment

            Working...