How to make a program using array?

Answer:
An array is a variable name that can store several values, not just one. Each element is accessed through the variable name, combined with a subscript - a number used to distinguish the elements in the array.

Basically you usually would do each of the following:
  • Declare the variable
  • Initialize the array, that is, assign values to each element
  • Retrieve the values at some later point
Here is an example with Java:

// The following will both declare an array, and assign initial values to it
int myArray = {5, 10, 15}
// The following will show each of the values:
for (int i = 0; i < myArray.length(); i++)
System.out.println("Element # " + i + " has the value " + myArray[i];

Note that in Java, the element numbering starts at zero.
First answer by ID3417421043. Last edit by Hilmarz. Contributor trust: 802 [recommend contributor recommended]. Question popularity: 1 [recommend question].