-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFibonacci2.java
More file actions
33 lines (32 loc) · 808 Bytes
/
Fibonacci2.java
File metadata and controls
33 lines (32 loc) · 808 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
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package recursion;
import java.util.*;
/**
*
* @author Samim
*/
public class Fibonacci2 {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n;
System.out.println("Enter The Number Of Terms :");
n=sc.nextInt();
for(int i=0;i<n;i++){
System.out.println(fibonacci(i)+"");
}
}
public static int fibonacci(int n){
if(n<=1)
{
return n;
}
else
{
return fibonacci( n-1)+fibonacci(n-2);
}
}
}