import cs1.Keyboard; /** Display the first n numbers of the Fibonacci sequence. @author Greg Vogl last modified 2003-09-22 */ public class Fibonacci { /** Display the first n numbers of the Fibonacci sequence. */ public static void main (String[] args) { System.out.println("Display the first n numbers of the Fibonacci sequence."); // get input System.out.println("Type an integer and press Enter."); long n = Keyboard.readInt(); // output numbers System.out.println("The first " + n + " Fibonacci numbers are:"); long f1 = 1; if (n > 0) System.out.print(1 + " "); long f2 = 1; if (n > 1) System.out.print(1 + " "); long f; for (int i=3; i<=n; i++) { f = f1 + f2; f2 = f1; f1 = f; System.out.print(f + " "); } // end with a new line System.out.println(""); } }