9Google AdSense

write a program to display the fibonacee series of n numbers.

import java.io.*;

public class Fibo
{
    public static void main(String a[])
   {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String str;
        int i;
        int ary[];
        ary=new int[100];
        try{      
               System.out.println("Enter the number N : ");
               str=br.readLine();
               i=Integer.parseInt(str);
               ary[1]=1;
               ary[2]=2;
               for(int lp=3;lp<=i;lp++)
                   ary[lp]=ary[lp-1]+ary[lp-2];
              
               System.out.println("Fibonacee series : ");
               for(int ji=1;ji<=i;ji++)
                    System.out.print(" "+ary[ji]);
           }
        catch(Exception e)  {  }
   }
}

No comments: