Results 1 to 15 of 15
Thread: fibonnaci number between limits?
- 09-25-2010, 04:32 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 29
- Rep Power
- 0
fibonnaci number between limits?
hi there,
i have been working on this applet program for the past 3-4 hours n i still cant figure out on what the error is! there appears to be an logical error in this programs(thought it generates few numberes between the limit).
Java Code:import java.applet.*; import java.awt.*; import java.awt.event.*; public class Main extends Applet implements ActionListener { TextField t1,t2,t3; Label label1,label2,label3; Button b; public void init() { t1=new TextField(10); t2=new TextField(10); t3=new TextField(10); label1=new Label("enter the lower limit"); label2=new Label("enter the upper limit"); label3=new Label("fibonnaci series are"); b=new Button("find"); add(label1); add(t1); add(label2); add(t2); add(label3); add(t3); add(b); b.addActionListener(this); } public void actionPerformed(ActionEvent e) { String s1="",s2="",s3="",str=""; int lower=0,upper=0,fib1=0,fib2=0,fib3=0,fib4=0,i; s1=t1.getText(); s2=t2.getText(); lower=Integer.parseInt(s1); upper=Integer.parseInt(s2); fib1=lower; fib2=lower+1; fib3=fib1+fib2; while(fib3<upper) { s2=str+" "+String.valueOf(fib3); fib1=fib2; fib2=fib3; fib3=fib1+fib2; } s1=String.valueOf(fib1)+" "+String.valueOf(fib2)+" "+s2; } }Last edited by Eranga; 09-25-2010 at 05:10 PM. Reason: code tags added
- 09-25-2010, 05:07 PM #2
Could you show the output for the program and explain what the problem with the output is and show what the output should be?
Your program documentation doesn't explain anything about what the program is to do or how it is going to do it.
- 09-25-2010, 05:12 PM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
And also please use code tags when you are posting again. Unformated codes are really hard to read.
- 09-25-2010, 05:17 PM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Did you know how to calculate the Fibonacci serious? Seems to me the logic you've build bu in your code is incorrect.
- 09-25-2010, 05:30 PM #5
Member
- Join Date
- Aug 2010
- Posts
- 29
- Rep Power
- 0
Hi,
thanks for the reply guys,i had modified the program before i posted the code,hence when i clickd on the find button that was supposed to generate fibonaci series ,it doesnt dispay anythin! :( :(.the logic luks proper to me though,i still cant figure out where i am going wrong! :(
Kind Regards
Manish87
- 09-25-2010, 05:33 PM #6
Member
- Join Date
- Aug 2010
- Posts
- 29
- Rep Power
- 0
Hi,
thanks for the reply guys,i had modified the program before i posted the code,hence when i clickd on the find button that was supposed to generate fibonaci series ,it doesnt dispay anythin! :( :(.the logic luks proper to me though,i still cant figure out where i am going wrong! :(
the ouput show be say like if i enter a lower limit say 6 and upper limit say 20,it should generate all the fibonaci numbers between 6 and 20
i.e 6,7,13
Kind Regards
Manish87
- 09-25-2010, 05:36 PM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Fine, then you've set the text into the relevant control, after the completion of the calculation.
Java Code:t3.setText(s1);
- 09-25-2010, 06:32 PM #8
Member
- Join Date
- Aug 2010
- Posts
- 29
- Rep Power
- 0
hey,
now the program displays the output but its incorrect
output:
lower limit : 1
upper limit:10
output: 5 8 8
- 09-25-2010, 06:51 PM #9
What should the output be?
Have you tried debugging your code by adding print outs of the variables and all the intermediate values as it computes them?
- 09-25-2010, 07:07 PM #10
Member
- Join Date
- Aug 2010
- Posts
- 29
- Rep Power
- 0
Hey,
the output was supposed to be 1,2,3,5,8 where 1 and 8 are lower and upper limit.the preceding values are added!
- 09-25-2010, 07:17 PM #11
Have you tried debugging your code by adding print outs of the variables and all the intermediate values as it computes them?
- 09-25-2010, 07:24 PM #12
Member
- Join Date
- Aug 2010
- Posts
- 29
- Rep Power
- 0
Hi,
since i started my applet last week itself i have not gone much of its details,hence i have not tryed out any debugging methods
i tryed to make the program more simplier.please check it but the problem still persist !
fib1=lower;
fib2=lower+1;
s1=String.valueOf(fib1)+" "+String.valueOf(fib2);
fib3=fib1+fib2;
while(fib3<upper)
{
s2=s1+" "+String.valueOf(fib3);
t3.setText(s1);
fib1=fib2;
fib2=fib3;
fib3=fib1+fib2;
}
- 09-25-2010, 07:33 PM #13
What are the all numbers that are generated by your code? Are they in the series?
Add print outs as the variables change and copy and paste them here. Be sure to show the name of the variable as well as its value in the print out.
- 09-26-2010, 07:16 PM #14
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
As I said earlier the logic that OP build in is incorrect.
- 09-27-2010, 07:26 AM #15
Member
- Join Date
- Sep 2010
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Finding a number in array close to another number
By SteroidalPsycho in forum New To JavaReplies: 2Last Post: 02-15-2010, 12:37 AM -
Printing the Number of Times a Number in a Range Shows up
By space4rent00 in forum New To JavaReplies: 1Last Post: 02-05-2010, 10:42 PM -
Java Limits?
By TexanProgrammer in forum New To JavaReplies: 10Last Post: 09-02-2009, 04:42 AM -
Geting Mobile Number, Mobile Operator, Location and Mobile Serial Number by J2ME.
By maruffaiz in forum CLDC and MIDPReplies: 1Last Post: 08-07-2009, 12:14 PM -
how to extract the number of the image which looks like a number
By Crest.Boy in forum Java ServletReplies: 1Last Post: 11-03-2008, 02:38 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks