0
0
Javaprogramming~15 mins

Array length property in Java - Mini Project: Build & Apply

Choose your learning style8 modes available
folder_codeArray length property
📖 Scenario: You are working on a simple inventory system for a small store. You have a list of product names stored in an array. You want to find out how many products are currently in the inventory.
🎯 Goal: Build a Java program that creates an array of product names, uses the length property to find the number of products, and prints the total count.
📋 What You'll Learn
Create a String array called products with exactly these values: "Apples", "Bananas", "Oranges", "Grapes", "Peaches"
Create an integer variable called totalProducts and set it to the length of the products array using the length property
Print the value of totalProducts to show how many products are in the array
💡 Why This Matters
🌍 Real World
Arrays are used to store lists of items like product names, customer names, or scores in many real-world applications.
💼 Career
Knowing how to use arrays and their length property is fundamental for software development jobs that involve data handling and processing.
Progress0 / 4 steps
1
Create the products array
Create a String array called products with these exact values: "Apples", "Bananas", "Oranges", "Grapes", "Peaches"
Java
💡 Need a hint?

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

2
Create the totalProducts variable
Create an integer variable called totalProducts and set it to the length of the products array using the length property
Java
💡 Need a hint?

Use products.length to get the number of items in the array.

3
Print the total number of products
Write a System.out.println statement to print the value of totalProducts
Java
💡 Need a hint?

Use System.out.println(totalProducts); to display the number.

4
Run the program to see the output
Run the program and check that it prints 5, the number of products in the array
Java
💡 Need a hint?

The output should be the number 5 because there are five products in the array.