FileDocCategorySizeDatePackage
FibonacciWriter.javaAPI DocExample862Sun Mar 28 19:07:02 BST 1999None

FibonacciWriter

public class FibonacciWriter extends Thread

Fields Summary
DataOutputStream
theOutput
int
howMany
Constructors Summary
public FibonacciWriter(OutputStream out, int howMany)

    theOutput = new DataOutputStream(out);
    this.howMany = howMany;
  
public FibonacciWriter(OutputStream out)

    this(out, Integer.MAX_VALUE);
  
Methods Summary
public voidrun()


    try {
      int f1 = 1;
      int f2 = 1;
      theOutput.writeInt(f1);
      theOutput.writeInt(f2);
  
      // now calculate the rest
      for (int i = 2; i < howMany; i++) {
        int temp = f2;
        f2 = f2 + f1;
        f1 = temp;
       if (f2 < 0) { // overflow
         break;
       }
        theOutput.writeInt(f2);
      }
    }
    catch (IOException e) {
      System.err.println(e);
    }