Skip to content

Commit b27f9d5

Browse files
committed
fibonaci
1 parent a8cf65a commit b27f9d5

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

Methods/Fibbonaci.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
/*
3+
* WAP in Java Fibbonaci series
4+
*
5+
*
6+
* Recursion
7+
*/
8+
9+
package basic;
10+
11+
import java.util.Scanner;
12+
13+
public class Fibbonaci {
14+
15+
public static int fibo(int n) {
16+
17+
if (n == 0 || n == 1) {
18+
return n;
19+
} else {
20+
21+
return fibo(n - 1) + fibo(n - 2);
22+
}
23+
}
24+
25+
public static void main(String[] args) {
26+
// TODO Auto-generated method stub
27+
28+
Scanner sc = new Scanner(System.in);
29+
System.out.println("Enter the n th Term ");
30+
int n = sc.nextInt();
31+
32+
System.out.println("The " + n + "term of fibonacci number is = " + fibo(n));
33+
34+
System.out.println("Fibonacci Series up to " + n + "term ");
35+
36+
for (int i = 0; i <= n; i++) {
37+
System.out.println(fibo(i));
38+
}
39+
40+
}
41+
42+
}

0 commit comments

Comments
 (0)