package lab3;

import java.util.Scanner;

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

        Scanner in = new Scanner(System.in);

        System.out.print("Enter how many numbers to sum: ");
        int count = in.nextInt();

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

        int found = 0;
        int number = 1;
        int sum = 0;

        for (; found < count; number++) {
            if (number % 5 == 2 || number % 3 == 1) {
                System.out.print(number + " ");
                sum += number;
                found++;
            }
        }

        System.out.println();
        System.out.println("Sum = " + sum);

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

        found = 0;
        number = 1;
        sum = 0;

        while (found < count) {
            if (number % 5 == 2 || number % 3 == 1) {
                System.out.print(number + " ");
                sum += number;
                found++;
            }
            number++;
        }

        System.out.println();
        System.out.println("Sum = " + sum);

        in.close();
    }
}
