-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFibonacci.java
More file actions
35 lines (33 loc) · 772 Bytes
/
Fibonacci.java
File metadata and controls
35 lines (33 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// import java.util.*;
// public class Fibonacci
// {
// public static void main(String args[])
// {
// int a=0,b=1,i=0;
// Scanner sc=new Scanner(System.in);
// int n=sc.nextInt();
// System.out.println("Number of terms are "+n);
// System.out.print(a +" ");
// while (i <= n)
// {
// int sum = a + b;
// a = b;
// b = sum;
// i++;
// System.out.print(sum +" ");
// }
// }
// }
//using recursion
import java.util.*;
public class Fibonacci{
static int fib(int n){
if(n<=1)
return n;
return fib(n-1)+fib(n-2);
}
public static void main(String args[]){
int n=9;
System.out.println(fib(n));
}
}