From b4ab197eb15f8f37f6d73c4941ac1577990c40de Mon Sep 17 00:00:00 2001 From: Nishanth Chandra <104753233+ThisIsNishanth@users.noreply.github.com> Date: Tue, 3 Jan 2023 18:41:05 +0530 Subject: [PATCH] Added a new Java Recursive program. --- algorithms/Java/recursion/Fibonacci.java | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 algorithms/Java/recursion/Fibonacci.java diff --git a/algorithms/Java/recursion/Fibonacci.java b/algorithms/Java/recursion/Fibonacci.java new file mode 100644 index 00000000..fea42dbf --- /dev/null +++ b/algorithms/Java/recursion/Fibonacci.java @@ -0,0 +1,25 @@ +package com.dsa; + +/* Description: To find the Nth Fibonacci Number + + Time Complexity: O(n) where n is the number inputted + */ + +public class Fibonacci { + public static int Fibo(int n){ + if(n < 2){ // base condition + return n; + } + return Fibo(n-1) + Fibo(n-2); //linear recurrence relation + } + public static void main(String[] args) { + System.out.println(Fibo(5)); + } + + /* Sample Input + n = 5 + + Output: + 5 + */ +}