Fibonacci Series Using Java With I/O Stream

Introduction

In this blog, I will explain about a Fibonacci series program, using Java I/O stream. It is very simple in Java programming. The output will be displayed in the Run module.

Software Requirement

JDK1.3.

Simple program

  1. import java.io.*;  
  2.   
  3. class fib  
  4.  {  
  5.    public static void main(String arg[]) throws IOException  
  6.     {  
  7.       int f1=-1,f2=1,f3,i,n;  
  8.   
  9.       String s = new String();  
  10.   
  11.       DataInputStream dr = new DataInputStream(System.in);  
  12.   
  13.       System.out.println("emter the number : ");  
  14.   
  15.       s = dr.readLine();  
  16.   
  17.         n=Integer.parseInt(s);  
  18.   
  19.            for(i=0;i<n;i++)  
  20.             {  
  21.               f3 = f1+f2;  
  22.                 System.out.println(f3);  
  23.                   f1=f2;  
  24.                   f2=f3;  
  25.             }  
  26.       }  
  27.   } 
Explanation

In this blog, I explained about a Fibonacci series program, using Java I/O Stream. The output will be displayed in the Run module.

Output

Ebook Download
View all
Learn
View all