[SOLVED] Problem with my program

• 12-15-2008, 08:48 AM
Mika
[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.
• 12-15-2008, 09:02 AM
Eranga
You want to fins the fibonacci in a Java code, is it? What you have done so far?
• 12-15-2008, 03:09 PM
Nicholas Jordan
he cannot get started. - code for recursion is thus:
Code:

```void recurse(int value) {   while (value > 0)   {       recurse(--value); } }```
.....
• 12-15-2008, 07:33 PM
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
• 12-17-2008, 04:11 AM
Eranga
Quote:

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...
• 12-17-2008, 05:19 AM
Mika
Thank for the code. I already submit a correct code to my instructor.
• 12-17-2008, 05:21 AM
Eranga
So you have solved the problem. If so please mark it as solved from the thread tools.
• 12-17-2008, 05:29 AM
Mika
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);
}
}
}
• 12-17-2008, 05:32 AM
Eranga
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.
• 12-17-2008, 05:38 AM
Mika
Thank you very much..