forked from CodeToExpress/dailycodebase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFibonacci.java
More file actions
26 lines (21 loc) · 706 Bytes
/
Copy pathFibonacci.java
File metadata and controls
26 lines (21 loc) · 706 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
import java.util.Scanner;
/**
* Nth element of fibonacci series using recursion
* @author MadhavBahlMD
* @date 18/01/2019
*/
public class Fibonacci {
public static int findElement (int num) {
if (num <= 2) return 1;
return findElement(num-1) + findElement(num-2);
}
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
System.out.println("/* ===== Fibonacci using recursion ===== */");
// Take the input
System.out.print("\nEnter the value of n: ");
int n = input.nextInt();
// Print the result
System.out.println(n + "th number of fibonacci series is: " + findElement(n));
}
}