004-005-009
Initialize Array with Literal
Medium
Problem Description
Initialize Array with Literal
In this problem, you will read 3 strings from standard input (one per line), then use array literal syntax to declare and initialize String[] fruits = {first, second, third} in one step, and print each element to standard output.
Input Format:
- Line 1: First string
- Line 2: Second string
- Line 3: Third string
Output Format:
- Print each array element on its own line in order
Learning Objectives:
- Read string values from standard input using
Scanner - Use array literal syntax to declare and initialize an array in a single statement
- Access each element of a string array by index
- Understand the recommended pattern for initializing arrays with known values
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