Java Recursion Program Practise 2 - Fibonacci Series

Java program to find the given term of Fibonacci Series using Recursion Function

Output

import java.util.*;
class Main {
    
    int fib(int n){
        if(n==1){
        return 0;
        }
        if(n==2){
        return 1;
        }
        if(n>2){
            return(fib(n-2)+fib(n-1));
        }
        else
        return -1;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a;
        System.out.println("Enter the number of terms of Fibonacci series to be displayed using Recursion function");
        a = in.nextInt();
        Main ob = new Main();
       System.out.println(ob.fib(a));
        
        
        
    }
}

Comments

Translate

Popular posts from this blog

Letter to SBI Bank Manager of Local Branch to reduce the interest rate on home loan

Abhisara - the Tryst Notes

Imagine that you were all alone at home on a winter night. Suddenly there was thunder, lightning and heavy rain. There was no electricity, and the inverter in your house stopped working. Narrate how you felt and what you did at that time.

Java Recursion Program Practise 5 - to input a number and print the sum of digits of the number

Summers are becoming hotter with each passing year. Write a description of one such very hot day. What did you see and hear as you walked outside? How were birds and animals affected?

Java String Manipulation 28th Jan Practice 1 - to accept a character and check whether it is a letter or not. If letter, then convert it to uppercase or lowercase. Also check whether it is letter or a special character

Java Recursion Program Practise 4 - to input a number and display sum from 1 to that number

Java Recursion Program Practise 3 - Raising base to power of index

Java Recursion Program Practise 1 - Factorial