Loop initialization, condition, update
📖 Scenario: You are helping a small shop owner count the total number of items sold in a day. The shop owner has a list of daily sales numbers for 5 different products.
🎯 Goal: Build a Java program that uses a for loop with proper initialization, condition, and update to sum the total items sold.
📋 What You'll Learn
Create an integer array called
sales with exactly these values: 3, 7, 2, 5, 4Create an integer variable called
total and set it to 0Use a
for loop with int i = 0 as initialization, i < sales.length as condition, and i++ as updateInside the loop, add
sales[i] to totalPrint the value of
total after the loop💡 Why This Matters
🌍 Real World
Counting totals from lists of numbers is common in stores, inventories, and reports.
💼 Career
Understanding loops and array processing is essential for software development and data handling jobs.
Progress0 / 4 steps