package lab3;

import java.util.Scanner;

public class Example3 {
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        System.out.print("Enter number of Fibonacci elements: ");
        int n = in.nextInt();

        // ===== Version 1: for loop =====
        System.out.println("Fibonacci sequence (for loop):");

        int a = 1;
        int b = 1;

        if (n >= 1) {
            System.out.print(a + " ");
        }
        if (n >= 2) {
            System.out.print(b + " ");
        }

        for (int i = 3; i <= n; i++) {
            int c = a + b;
            System.out.print(c + " ");
            a = b;
            b = c;
        }

        System.out.println();

        // ===== Version 2: while loop =====
        System.out.println("Fibonacci sequence (while loop):");

        a = 1;
        b = 1;
        int count = 1;

        while (count <= n) {
            if (count == 1 || count == 2) {
                System.out.print("1 ");
            } else {
                int c = a + b;
                System.out.print(c + " ");
                a = b;
                b = c;
            }
            count++;
        }

        in.close();
    }
}
