Fibonnaci Numbers

import java.util.Scanner;

/**
*
*/

/**
* @author asharda
*
*/
public class fibonaccinumber {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(“Enter a number for which you want a fibonnaci number”);
Scanner in=new Scanner(System.in);
int number=generatenumber(in.nextInt());
System.out.println(“Fibonnaci Number is “+number);

}

public static int generatenumber(int n)
{int sum;

if(n==0)
return 0;
else if(n==1)
return 1;
else

return generatenumber(n-1) +generatenumber(n-2);

}

}

Advertisements

About qainterviews

Software Geek,QA Expert,Blogger
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s