This project simulates the display of available seating in a cinema row. It utilizes a While Loop to iterate through seat numbers starting from 2, incrementing by 2, until reaching the limit of 10.
The goal is to understand loop control with custom step increments and inclusive boundary conditions.
Task 46: Output seat numbers starting from 2, with a step of 2, up to 10 inclusive.
Requirements:
- Initialize an
intvariable for the seat number. - Use a
whileloop that continues until the seat number is less than or equal to 10. - Print each seat number on a new line.
- Increment the seat number by 2 in each iteration.
- Conditional Iteration: Implementation of logic that handles specific numerical ranges.
- Arithmetic Incrementation: Using the addition assignment operator (
+=) to manage step logic. - Boundary Control: Effective use of the "less than or equal to" (
<=) operator to ensure the final value is processed.
- Logic Flow: The loop starts at 2, checks if it's within the range, prints, and jumps directly to the next even number.
- Efficiency: By incrementing by 2 instead of checking every number with an
ifstatement, the loop performs fewer iterations.
- Even Number Sequence: Automatically generates a list of even values within a set range.
- Inclusive Logic: Correctly identifies and outputs the upper limit (10) as per requirements.
- Minimalistic Design: Achieves the result with a single variable and straightforward loop logic.
2
4
6
8
10
Project Structure:
src/com/yurii/pavlenko/
└── CinemaSeats.java # Main Entry Point & Logic
Code
package com.yurii.pavlenko;
public class CinemaSeats {
public static void main(String[] args) {
int seatNumber = 2;
while (seatNumber <= 10) {
System.out.println(seatNumber);
seatNumber += 2;
}
}
}This project is licensed under the MIT License.
Copyright (c) 2026 Yurii Pavlenko
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files...
License: MIT