Java Fibonacci number generator

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

    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

    • #17
      tool
      JKPolk
      • Aug 2003
      • 3737

      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

      • #18
        FFR Player
        gerbi7
        • Feb 2006
        • 276

        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

        • #19
          tool
          JKPolk
          • Aug 2003
          • 3737

          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

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

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