Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Java Programs 14: Java Program to Print Fibonacci Series of Given Length Using Recursion

Posted on 02/19/2025 By admin

Hello Folks,

This is a frequently asked programming interview question to print a fibonacci series of given length.

In previous post, we have seen printing fibonacci series using iterative logic with collection concept. This will be acceptable for freshers but not for experienced, interviewer expects recursion logic.  This post explains in details how recursion takes place in finding fibonacci series. I assume you should have basic idea about recursion.

Basic definition of Recursion:

Recursion is a programming technique in which a method calls itself till an exit point is satisfied to solve a problem. You can refer this link to know basics of recursion with simple example.

Fibonacci series:

Wikipedia defines it very well.

The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones:

Often, especially in modern usage, the sequence is extended by one more initial term:

By definition, the first two numbers in the Fibonacci sequence are either 1 and 1, or 0 and 1, depending on the chosen starting point of the sequence, and each subsequent number is the sum of the previous two.

To write recursive method we need to decide two things: 1. Logic to find fibonacci number . (Every number after the first two is the sum of the two preceding ones) 2. Exit point/s where recursive method will be stopped recursion. ( When number position is 1st and 2nd as we know first fibonacci number is 1 and 2nd fibonacci number is 1. ) Recursive method for regression:

Understand by below image:

Output:

If you like my posts, please like, comment, share and subscribe.

#HappyCoding

Uncategorized

Post navigation

Previous Post: Independent-dependent concept in XPath Expression
Next Post: Postman Tutorial Part 49 – How to Upload an Image Using Postman

Related Posts

Project Structure – Make Selenium Easy Uncategorized
ExpreWithPackageTag – Make Selenium Easy Uncategorized
Untitled Diagram (1) – Make Selenium Easy Uncategorized
June 25, 2018 – Make Selenium Easy Uncategorized
How To Change Default Download Directory For Chrome Browser in Selenium WebDriver Uncategorized
xpathexample – Make Selenium Easy Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark