004-007-006
Enhanced For Loop: Product List Display
Easy
Problem Description
Enhanced for loop: Product List Display
In this problem, you will create a program that reads product names from standard input using Scanner and displays each product with a number using an enhanced for loop.
Learning Objective: Understand how to process arrays concisely using enhanced for loops (for-each)
Overview
Read the number of products and product names from standard input, then use an enhanced for loop to display each product with a number.
Input Format
N
product1
product2
...
productN
- Line 1: Number of products N (1 ≤ N ≤ 10)
- Lines 2+: Product names (English words)
Output Format
1: product1
2: product2
...
N: productN
Note: Enhanced for loops only provide element values, so manage numbering with a separate counter variable.
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up