# Recusion problem

• 12-15-2008, 09:31 AM
Mika
Recusion problem
Hi Everyone..
I' am a new member of this site. I have a problem with my program. We use recursion in creating a program called fibonacci. Our instructor give us this program last December 12, 2008. He wanted us to solve the lowest number and the higher number and display the answer and it will add the previous number. We use java programming language. The output will be like this:
11235813....
We use recursion in creating this program and I dont know how to start it.
Your help is well appreciated. Thank You.
• 12-16-2008, 08:12 AM
ptsofathrty
try this
public class Fibonacci {
private long number;
private int index;

public Fibonacci ( ) {
number = 0;
index = 0;
}

public static void main ( String [] args ) {
Fibonacci program = new Fibonacci ( );
program.GetIndex ( );
program.FindAndPrint ( );
}

public void GetIndex ( ) {
do {
System.out.print ( "\n\n\nEnter a Fibonacci index (1 to 25) -> " );
} while ( index < 1 || index > 25 );
}

public void FindAndPrint ( ) {
number = FindFib ( index );
System.out.println ( "The Fibonacci number at index " + index + " is: " + number );
}

public int FindFib ( int i ) {
// System.out.println ( i );
if ( i == 1 || i == 2 )
return 1;
else
return ( FindFib (i - 2) + FindFib(i - 1) );

}
}
• 12-16-2008, 01:58 PM
Mika
hi
hi,
Thank you for the program but it has 2 errors. line 17. It is said that cannot find symbol
location: class Fibonacci
• 12-16-2008, 02:07 PM
Mika
hi,
Thank you for the program but it has 2 errors. line 17. It is said that cannot find symbol
location: class Fibonacci
• 12-16-2008, 03:52 PM
CJSLMAN
@ptsofathrty: It's probably not a good idea to post complete code for the OPs. Too much temptation to cut & paste & forget (no learning involved). The purpose of this forum is for people to learn, not get free code. I'm pretty sure that Mika doesn't know what the code does because he/she hasn't figured out what the TextReader method is supposed to do or why it's failing.

CJSL
• 01-23-2009, 03:04 PM
exornextman
hello...... i have another problem, how could i display messages or statement in a JOptionPane which this JOptionPane was inside of a LOOP.... someone suggested to use ConfirmationDialog isntead of MessageDialog.... but my INSTRUCTOR said that I must use Message dialog because I`m only displaying the result.
ex. in BufferedReader the output is like this: 1 2 3 4 5, how could I display this in JoptionPane in the same way?
code:
"only the loop part"
[1] for(int countr=0; countr<=20; countr++){
System.out.print(" "+countr);
}
in this way there is no problem it will print 0 1 2 to 20;

[2]for(int countr=0; countr<=20; countr++){
JOptionPane.showMessageDialog(" "+countr);
}
in this way u need to click the OK before you can view the other numbers so you need to click OK 20 times;
HOW COULD I DISPLAY IT IN ONE JOPTIONPANE DIALOG THE 21 NUMBERS?