PROGRAM FOR FIBONACCI NUMBER

The Fibonacci sequence is a set of numbers that starts with a one or a zero, followed by a one, and proceeds based on the rule that each number (called a Fibonacci number) is equal to the sum of the preceding two numbers.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package pack;
java.util.Scanner;
public class FibonacciNumber
{
    public static void main(String args[])  
{  
    Scanner scr=new Scanner(System.in);
    System.out.println("Enter any number");
    int count=scr.nextInt();
 int n1=0,n2=1,n3;  
 System.out.print(n1+" "+n2);    
 for(int i=2;i<count;i++)   
 {    
  n3=n1+n2;    
  System.out.print(" "+n3);    
  n1=n2;    
  n2=n3;    
 }     
}
}  

Output :Fibonacci Number
IPPal