# Java Code for Fibonacci Series

In this post we will see Java Code for Fibonacci series. we will solve fibonacci series first with an algorithm then will write actual code in java.

## What is Fibonacci Series

A series where next number is the addition of previous two numbers is called as fibonacci series.

Example:

1 1 2 3 5 8 13 21 24………….

Here we can observe first letter is 1 and second letter is 1, if we add we get 2 which is the third number

ie 1+1=2

1+2=3

2+3=5

3+5=8

5+8=13

8+13=21

13+21=24

It continues …………….

## Algorithm For Fibonacci Series

1. Initialize first two numbers as 1 that is a=1,b=1
2. Next print first two numbers
3. Then add first 2 assign it to variable c. ie c=a+b
4. Print c
5. Now re-assign a=b and c=b.
6. Repeat from 4 until end
7. Congrats you just solved one problem, we have similar type of questions Click Here to take a look.

## Java Code For Fibonacci Series

```<strong>
// Code by DATTATREY PATIL

public class problem30 {

public static void main(String[] args) {
System.out.println("Fibonachi series ");
int a,b,c;
a=1;
b=1;

// Here we are printing 20 terms in fibonacci series
int n=20;
System.out.println(a);
System.out.println(b);
for(int i=0;i&lt;n;i++){
c=a+b;
System.out.println(c);
a=b;
b=c;

}
}
}
}</strong>```