All pastes #978931 Raw Edit

Miscellany

public java v1 · immutable
·published 2008-04-09 22:54 UTC
rendered paste body
// In the interfacePrimeGenerator pg = new PrimeGenerator(100) // Construct something to generate primes up to 100while (pg.hasNextPrime()){    System.out.println(pg.nextPrime())}// Generator for Fibonacci numberspublic class FibonacciGenerator{   private int fold1 = 0;   private int fold2 = 1;   private int fnew = 0;   public FibonacciGenerator()   {   }   public int nextNumber()   {      fnew = fold1 + fold2;      fold2 = fold1;      fold1 = fnew;      return fnew;   }}import java.util.Scanner;public class FibonacciRunner{   public static void main(String[] args)   {      Scanner in = new Scanner(System.in);      System.out.println("Enter n:");      int n = in.nextInt();      FibonacciGenerator fg = new FibonacciGenerator();      for (int i = 1; i <= n; i++)         System.out.println(fg.nextNumber());   }}