import java.util.*;
/**
*
* @author Akhter Wahab
*/
public class Main {
/**
* @param args the command line arguments
*/
public static long fib(int n) {
if (n <= 1) return n;
else return fib(n-1) + fib(n-2);
}
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int N = Integer.parseInt(scan.nextLine());//taking input from the user the limit of the Fibonacci series
for (int i = 1; i <= N; i++)
System.out.println(i + ": " + fib(i));
}
}
Recursion is used in this fibonacci finding class
ReplyDeleteOr maybe pass n in on the command line :/
ReplyDeleteyes definitely its a good suggestion thanks Anonymous...
ReplyDeletenow N can be taken form command line..4 finding Fibonacci series..
ReplyDelete