# Fibonacci series program in java

If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions.

Fibonacci series is numerical series in which next number is sum of previous two numbers.
For example :
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 etc.
There are two ways to print Fibonacci series.

• Using iteration
• Using recursion

### Using iteration:

#### Algorithm:

• Initialise first two terms with 0 and 1
• Find sum of first two terms.
• Iterate upto numberOfElements
• Print the sum
• Assign prev to next and next to sum to go for next two terms.

#### Program:

When you run above program, you will get following output:

💻 Awesome Tech Resources:
• Looking for ⚒️ tech jobs? Go to our job portal.
• Looking for tech events? Go to tech events 🗓️ Calendar.️

### Using recursion:

#### Algorithm:

• Initialise first two terms with 0 and 1
• Base case will be when numberOfElements becomes 0.
• Find sum of first two terms.
• Print the sum
• Assign prev to next and next to sum to go for next two terms.
• Call same function again and decrease numberOfElements.

#### Program:

When you run above program, you will get following output:
Please go through java interview programs for more such programs.

import_contacts

### You may also like: ## Related Posts

• 30 December

### Rock Paper Scissors Game in Java

Learn about how to implement Rock Paper Scissors game in java.

• 25 December

### Find automorphic number in java

Learn about how to find automorphic number in java using different methods

• 25 December

### Find nth prime number in java

Learn about how to find nth prime number in java.

• 06 October

### Implement distance formula in java

In this post, we will see how to implement distance formula between two points in java. Formula to find distance between two points ( x1, y1) and (x2 , y2) is d= sqrt( (x2-x1)^2+ (y2 – y1)^2) Here is simple program to calculate distance between two points in java. 💻 Awesome Tech Resources: Looking for […]

• 06 October

### Convert decimal to binary in java

In this post, we will see how to convert decimal to binary in java. There are lot of ways to convert decimal to binary in java.Let’s explore them one by one. 💻 Awesome Tech Resources: Looking for ⚒️ tech jobs? Go to our job portal. Looking for tech events? Go to tech events 🗓️ Calendar.️ […]

• 05 October

### Print prime numbers from 1 to 100 in java

In this program, we will print prime numbers from 1 to 100 in java. A prime number is a number which has only two divisors 1 and itself. To check if the number is prime or not, we need to see if it has any other factors other than 1 or itself. If it has, […]

## Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.