0
0
Javaprogramming~15 mins

For loop syntax in Java - Mini Project: Build & Apply

Choose your learning style9 modes available
For loop syntax
📖 Scenario: You are organizing a small event and want to print the names of all the guests attending.
🎯 Goal: Write a Java program that uses a for loop to print each guest's name from a list.
📋 What You'll Learn
Create an array of guest names
Use a for loop with an index variable i
Print each guest name inside the loop
💡 Why This Matters
🌍 Real World
Printing lists of names or items is common in event planning, inventory management, and many other tasks.
💼 Career
Understanding for loops is essential for iterating over data structures in software development.
Progress0 / 4 steps
1
Create the guest list array
Create a String array called guests with these exact names: "Alice", "Bob", "Charlie".
Java
Need a hint?

Use curly braces {} to list the names inside the array.

2
Add a loop counter variable
Inside the main method, create an integer variable called i and set it to 0 before the loop.
Java
Need a hint?

Declare int i = 0; before the loop starts.

3
Write the for loop to print guest names
Write a for loop using i starting at 0, running while i < guests.length, and incrementing i by 1 each time. Inside the loop, print guests[i].
Java
Need a hint?

Use for (i = 0; i < guests.length; i++) and inside the loop print guests[i].

4
Print the guest names
Run the program and print each guest name using System.out.println(guests[i]) inside the for loop.
Java
Need a hint?

Make sure to print each name inside the loop using System.out.println(guests[i]).