From 3b13d32339b9c09c47e024abb030342357649708 Mon Sep 17 00:00:00 2001 From: Priyanshu_M <72194769+Priyanshu95663@users.noreply.github.com> Date: Wed, 6 Oct 2021 13:58:35 +0530 Subject: [PATCH] Create fibonaccirecursive.java --- Recursion/fibonaccirecursive.java | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Recursion/fibonaccirecursive.java diff --git a/Recursion/fibonaccirecursive.java b/Recursion/fibonaccirecursive.java new file mode 100644 index 0000000..52ea3b5 --- /dev/null +++ b/Recursion/fibonaccirecursive.java @@ -0,0 +1,30 @@ +import java.util.*; +class fibonaccirecursive +{ + + public static int fib(int n) + + + { + if (n==1) + return 0; + else if(n==2) + return 1; + else if(n>2) + return fib(n-1)+fib(n-2); + else + return -1; + } + public static void main(String args[]) + { + Scanner sc=new Scanner(System.in); + int term; + int m=sc.nextInt(); + fibonaccirecursive obj=new fibonaccirecursive(); + for(int i=1;i<=m;i++) + { + term=obj.fib(i); + System.out.println(term+","); + } + } +}