020-001-002

List Management: Shopping List

Easy

Problem Description

List Management: Shopping List

In this problem, you will create a program that reads product names from standard input, stores them in an ArrayList, displays each item with a numbered label, and outputs the total count to standard output.

Learning Objective: Use ArrayList to manage multiple data and learn basic operations of add, get, and size

Read the number of products and each product name from standard input, storing them in an ArrayList<String> using add(). Then iterate over the list with a for loop, retrieving each element via get(i) to display it in [1] product name format, and finally output the total item count using size().

Input

Line 1: Number of products (integer, 1-10 items)
Lines 2~N+1: Product name (string)

Output

Shopping List:
[1] [product name 1]
[2] [product name 2]
...
Total Items: [number of products]

Test Cases

※ Output examples follow programming industry standards

Normal case
Input:
3
Milk
Bread
Eggs
Expected Output:
Shopping List:
[1] Milk
[2] Bread
[3] Eggs
Total Items: 3
Normal case
Input:
5
Apple
Banana
Orange
Grapes
Watermelon
Expected Output:
Shopping List:
[1] Apple
[2] Banana
[3] Orange
[4] Grapes
[5] Watermelon
Total Items: 5

Your Solution

Current Mode: My Code
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Write your code here

sc.close();
}
}
0 B / 5 MB

You have 10 free executions remaining