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. class fib {
  3. public static void main(String arg[]) throws IOException {
  4. int f1 = -1, f2 = 1, f3, i, n;
  5. String s = new String();
  6. DataInputStream dr = new DataInputStream(System.in);
  7. System.out.println("emter the number : ");
  8. s = dr.readLine();
  9. n = Integer.parseInt(s);
  10. for (i = 0; i < n; i++) {
  11. f3 = f1 + f2;
  12. System.out.println(f3);
  13. f1 = f2;
  14. f2 = f3;
  15. }
  16. }
  17. }
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
o