Program to find fibonacci series in java

Java code to print  Fibonacci series


import java.io.*;

class Test {

    public static void main(String[] args) throws IOException {

    int i=0,j=1,k=2,r,f;
    System.out.println("Enter the range:");
    BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
    r=Integer.parseInt(br.readLine());
    System.out.println("FIBONACCI SERIES: ");
    System.out.println(i);
    System.out.println(j);

    while(k > 0){
            f=i+j;
            i=j;
            j=f;
            System.out.println(j);
            k++;
    }
  }

}
Post a Comment