0
0
Javaprogramming~15 mins

Two-dimensional arrays in Java - Mini Project: Build & Apply

Choose your learning style8 modes available
folder_codeWorking with Two-Dimensional Arrays in Java
📖 Scenario: You are organizing a small seating chart for a classroom. The classroom has 3 rows and 4 columns of seats. Each seat can hold the name of one student.
🎯 Goal: You will create a two-dimensional array to store student names, set up a helper variable for the number of rows, fill the array with student names, and finally print the seating chart.
📋 What You'll Learn
Create a two-dimensional array of strings called seatingChart with 3 rows and 4 columns.
Create an integer variable called rows and set it to 3.
Fill the seatingChart array with the exact student names provided.
Use nested for loops with variables i and j to print each student's name in the seating chart.
💡 Why This Matters
🌍 Real World
Two-dimensional arrays are useful for storing grid-like data such as seating charts, game boards, or tables.
💼 Career
Understanding two-dimensional arrays is important for software development roles that involve data organization, UI layouts, or matrix computations.
Progress0 / 4 steps
1
Create the two-dimensional array
Create a two-dimensional array of strings called seatingChart with 3 rows and 4 columns.
Java
💡 Need a hint?

Use new String[3][4] to create the array with 3 rows and 4 columns.

2
Add a variable for the number of rows
Add an integer variable called rows and set it to 3.
Java
💡 Need a hint?

Declare int rows = 3; to store the number of rows.

3
Fill the seating chart with student names
Fill the seatingChart array with these exact student names in order by row and column:
"Alice", "Bob", "Charlie", "Diana" in row 0,
"Ethan", "Fiona", "George", "Hannah" in row 1,
and "Ian", "Jane", "Kyle", "Laura" in row 2.
Java
💡 Need a hint?

Assign each student name to the correct position using seatingChart[row][column] = "Name";.

4
Print the seating chart
Use nested for loops with variables i and j to print each student's name from seatingChart. Print each row on a new line with names separated by spaces.
Java
💡 Need a hint?

Use for (int i = 0; i < rows; i++) and inside it for (int j = 0; j < seatingChart[i].length; j++) to print names with System.out.print and a space. Use System.out.println() after each row.