004-005-010

Array Initialization with Literals

Easy

Problem Description

array Initialization with Literals

In this problem, you will create a program that initializes a String array using array literals (curly brace notation) and displays the element at the index read from standard input.

Learning Objective: Understand array initialization using array literals and element access by index

Overview

Initialize an array using array literals (curly brace notation) and output the element at the index read via Scanner.

Input Format

n
  • n: Index of the element to output (integer, 0 to 2)

Specifications

  • Initialize a String array with {"Apple", "Banana", "Cherry"}
  • Read integer n using Scanner
  • Output the element at index n

Input/Output Example

Input:

1

Output:

Banana

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