004-002-013

Array Creation: Dynamic Size

Hard

Problem Description

Array Creation: Dynamic Size

In this problem, you will create a program that reads an integer size from standard input, uses it to dynamically create an integer array data, and displays the array length and the indices of the first and last elements to standard output.

Learning Objective: Understand how to read input with Scanner and dynamically determine array size

Overview

Create a program that reads a value from standard input and uses it to determine array size.

Specifications

  • Read one integer from standard input and assign it to variable size
  • Create an integer array data using size
  • Output the array length
  • Output the first and last element indices

Input Format

size (integer)

Output Format

Array created with size: <size>
First index: 0
Last index: <size-1>

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