Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

fibonacci sequence code

807600Nov 28 2007 — edited Nov 28 2007
my code does not work its suppose to print out for the nth interger given by the user
for example if the user inputs 4 the code is suppose to print out 1,2,1,5,1.66
public static int fib(int n){

int a =1;
int b =1;
int c =a+b;
for(int i=0; i<=n; i++){
int d = a+b;
a=b;
b=d;
}
return b;
}
public static void main(String[]args){
String input = JOptionPane.showInputDialog("Enter n: ");
int n = Integer.parseInt(input);
int d= fib(n+1)/fib(n)
for(int i=2; i<=n; i++){

	System.out.println((double)d);
}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 26 2007
Added on Nov 28 2007
11 comments
261 views