# Java program to Generate Fibonacci sequence

follow A series of numbers in which each number is the sum of the two preceding numbers.

rencontres musicales de méditerranée bastia 2012 for example 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 etc. The first two numbers of fibonacci series are 0 and 1.

### Algorithm:

https://infotuc.es/esminec/332 Step 1: START.

its its rencontre Step 2: Declare variables a,b,c.

enter Step 3: Initialize the variables.

Step 4: Enter no of terms of terms of fibonacci series to be printed.

Step 5: Print a,b.

Step 6: Use loop for the following steps

c=a+b

a=b

b=c

Step 7: Print c.

Step 8: STOP.

### Source code:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import java.util.*; class Fibonacci { public static void main(String args[]) { int a=0; int b=1; int c=0; System.out.println("\n \n *** www.programmingposts.com *** \n \n"); System.out.println("<< JAVA program to Generate Fibonacci series >> \n\n "); System.out.println("Enter the range:"); Scanner scanner = new Scanner(System.in); int range=scanner.nextInt(); System.out.print(a); System.out.print(" "+b); for(int i=2;i<range;i++) { c=a+b; System.out.print(" " +c); a=b; b=c; } } } |

### Explanation:

- a, b, c – These integer variables are used for the calculation of Fibonacci series. The values of a, b and c are initialized to 0, 1 and 0 respectively.
- range – This integer is the limit determining the number of elements of Fibonacci series that should be calculated.
- i – This is the loop variable.

**rencontrer des femmes en ukraine Process for i = 2**

**follow**First we update the value of c (initially 0) with the following expression –**http://captainaugust.com/?koooas=forex-robot&318=07 c = a + b**. So after this c = 0+ 1 = 1 (Third value of Fibonacci series).- Then we print the value of c.
- At last we update the value of a as –
**http://ortdestreffens.de/?yabloko=binary-options-banc-de-swiss&b74=30 “a = b”**and then the value of b as –**“b = c”**. So after this step a = 1 and b = 1.

This process continues till the condition in the loop gets satisfied.

### Output:

C:\Users\santo\Desktop\new>javac Fibonacci.java

C:\Users\santo\Desktop\new>java Fibonacci

*** www.programmingposts.com ***

<< JAVA program to Generate Fibonacci series >>

Enter the range:

6

0 1 1 2 3 5