0
0
Javaprogramming~15 mins

Nested for loop in Java - Mini Project: Build & Apply

Choose your learning style9 modes available
Nested for loop
📖 Scenario: You are organizing a small event where you want to print a seating chart. The chart shows rows and seats in each row.
🎯 Goal: Build a Java program that uses nested for loops to print seat labels for 3 rows and 4 seats per row.
📋 What You'll Learn
Create a variable for the number of rows
Create a variable for the number of seats per row
Use nested for loops to generate seat labels
Print each seat label in the format 'Row X Seat Y'
💡 Why This Matters
🌍 Real World
Nested loops are useful when you need to work with grids, tables, or any situation with rows and columns, like seating charts or calendars.
💼 Career
Understanding nested loops is important for programming tasks that involve multi-dimensional data, such as game development, data analysis, and user interface design.
Progress0 / 4 steps
1
Create variables for rows and seats
Create an int variable called rows and set it to 3. Create another int variable called seatsPerRow and set it to 4.
Java
Need a hint?

Think of rows as how many rows of seats you have, and seatsPerRow as how many seats are in each row.

2
Start the outer for loop for rows
Write a for loop with variable row that starts at 1 and runs while row <= rows, increasing row by 1 each time.
Java
Need a hint?

The outer loop controls the rows. Start counting rows from 1 up to the number of rows.

3
Add the inner for loop for seats
Inside the for loop for row, write another for loop with variable seat that starts at 1 and runs while seat <= seatsPerRow, increasing seat by 1 each time.
Java
Need a hint?

The inner loop counts seats in each row from 1 up to seatsPerRow.

4
Print seat labels inside inner loop
Inside the inner for loop, write a System.out.println statement that prints the seat label in the format: "Row " + row + " Seat " + seat.
Java
Need a hint?

Use System.out.println to print each seat label with the row and seat numbers.