# Thread: [SOLVED] Problem with my program

1. Member
Join Date
Dec 2008
Location
Davao Oriental
Posts
29
Rep Power
0

## [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. he cannot get started. - code for recursion is thus:
Java Code:
void recurse(int value)
{
while (value > 0)
{
recurse(--value);
}
}
.....

3. Member
Join Date
Dec 2008
Posts
25
Rep Power
0
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

4. Originally Posted by angelicsign
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...

5. Member
Join Date
Dec 2008
Location
Davao Oriental
Posts
29
Rep Power
0
Thank for the code. I already submit a correct code to my instructor.

6. Member
Join Date
Dec 2008
Location
Davao Oriental
Posts
29
Rep Power
0
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);
}
}
}

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

8. Member
Join Date
Dec 2008
Location
Davao Oriental
Posts
29
Rep Power
0
Thank you very much..

#### Posting Permissions

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