Results 1 to 10 of 10
  1. #1
    Mika is offline Member
    Join Date
    Dec 2008
    Location
    Davao Oriental
    Posts
    29
    Rep Power
    0

    Red face [SOLVED] Problem with my program

    Hi everyone..
    I' am a new member of this site. I have a problem with my program.
    Our instructor give us a program that will add the lowest number to higher number and it will display the answer and that answer will add from the previous number. It is called Fibonacci.
    Example:
    Output of the code:
    112358....
    It depend on number entered by the user when to stop the program.

    Your help is very well appreciated. Thank you.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  3. #3
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    he cannot get started. - code for recursion is thus:
    Java Code:
    void recurse(int value)
    {
       while (value > 0)
       {
           recurse(--value);
    }
    }
    .....
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  4. #4
    angelicsign is offline Member
    Join Date
    Dec 2008
    Posts
    25
    Rep Power
    0

    Default

    ya, you need a recursive function to make your job done.
    but have to do some algorithm inside the function,
    the puzzle have to complete by yourself.
    can you show me original question?
    i also want to try it..
    can do some revision about recursion.:p

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by angelicsign View Post
    ya, you need a recursive function to make your job done.
    but have to do some algorithm inside the function,
    the puzzle have to complete by yourself.
    can you show me original question?
    i also want to try it..
    can do some revision about recursion.:p
    I think he wants to display each digit of a give number from lowest to higher, using recursion. If so what he's going to do with Fibonacci...

  6. #6
    Mika is offline Member
    Join Date
    Dec 2008
    Location
    Davao Oriental
    Posts
    29
    Rep Power
    0

    Default

    Thank for the code. I already submit a correct code to my instructor.

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  8. #8
    Mika is offline Member
    Join Date
    Dec 2008
    Location
    Davao Oriental
    Posts
    29
    Rep Power
    0

    Default

    public class Fibonacci {
    public static void main(String []args) {
    for (int i=1;i<=10;i++)
    System.out.print(fib(i)+", ");
    }
    public static int fib(int n) {
    if(n<2) {
    return n;
    }
    else {
    return fib(n-1) + (n-2);
    }
    }
    }

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    You can use code tags to post code segments next time here in the forum. Formatted codes are easy to read. Read our FAQ page for more information.

  10. #10
    Mika is offline Member
    Join Date
    Dec 2008
    Location
    Davao Oriental
    Posts
    29
    Rep Power
    0

Similar Threads

  1. Problem with my first Struts program....please help me
    By sireesha in forum Web Frameworks
    Replies: 5
    Last Post: 10-16-2011, 04:19 PM
  2. DaysAndMonth program problem Help!!
    By kris09 in forum New To Java
    Replies: 1
    Last Post: 08-04-2008, 06:11 PM
  3. program problem
    By amith in forum AWT / Swing
    Replies: 12
    Last Post: 05-16-2008, 08:07 PM
  4. Problem with First Hibernate program
    By sireesha in forum JDBC
    Replies: 11
    Last Post: 05-05-2008, 04:19 PM
  5. Problem with my program HelloWorld
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-05-2007, 05:32 PM

Posting Permissions

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