Java Program:

- To print fibonacci series

Example:

User Input: 5

Output:
Fibonacci series : 0 1 1 2 3 5

import java.util.Scanner;
public class Fibonacci {
  public static void main(String []args) {
    int num.a=0,b=1,next;
    Scanner userInput = new Scanner(System.in);
    System.out.print("Enter fibonacci series nth term : ");
    num = userInput.nextInt();
    
    System.out.print("Your fibonacci series : ");
    for(int i=0; i<num; i++) {
      System.out.print(a+" ");
      next=a+b;
      a=b;
      b=next;
    }
  }
}

Output:

  Enter fibonacci series nth term : 8
  Your fibonacci series : 0 1 1 2 3 5 8 13
Program
number

You should know first :

Fibonacci Series : Series of numbers in which each number is the sum of the last 2 numbers

//Initially a & b :holds 1st & 2nd terms of fibonacci series
for(int i=0; i<num; i++) {
  System.out.print(a+" ");
  next=a+b;
  a=b;
  b=next;
}
Concept

Coming Soon !

Quick
Tutorial

Quote

We are all now connected by the Internet, like neurons in a giant brain.