Fibonacci Series > Java Program

Analysis of Algorithm

Fibonacci Series > Java Program


import java.util.*; 

class Fibonacci 
{  
public static void main(String args[])throws Exception  
{   

int f,q,i=0;   
Scanner sc=new Scanner(System.in);   
System.out.println("Enter a number: ");   
f=sc.nextInt();   
int a=0,b=1;   
System.out.println("Fibonacci : "+a);   
System.out.println("Fibonacci : "+b);   
while(i!=f-2)   
{    
q=a+b;    
a=b;    
b=q;    
System.out.println("Fibonacci : "+q);   
i++;           
}  


/* Output:
Enter a number: 5 
Fibonacci : 0 
Fibonacci : 1 
Fibonacci : 1 
Fibonacci : 2 
Fibonacci : 3 
Fibonacci : 5   */

Comments

Popular posts from this blog

Intermediate Code Generation > C Program