Download Text11-Arrays - Vernon Computer Science

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts

Linked list wikipedia , lookup

Comparison of programming languages (associative array) wikipedia , lookup

Array data structure wikipedia , lookup

Transcript
Figure 11.6
// Java1104.java
// This program has the same <list> array and the same <list> values as the previous program.
// This time the array declaration and allocation is accomplished with a single statement.
public class Java1104
{
public static void main(String args[])
{
System.out.println("Java1104\n");
int list[] = new int[10];
for (int index = 0; index <=9; index++)
list[index] = index + 100;
for (int index = 0; index <=9; index++)
System.out.print(list[index] + " ");
}
}
Java1104
100 101 102 103 104 105 106 107 108 109
Figure 11.7 pulls the array declarations from two previous programs. The first
example uses two statements. The second example combines the two statements
into one. The one-statement approach is more commonly used.
Figure 11.7
Declaring an array with two program statements
int list[ ];
list = new int[10];
Declaring an array with one program statement
int list[ ] = new int[10];
It is not necessary to declare the size of an array if an initializer list is used.
Program Java1105.java, in figure 11.8, shows a set of integer values placed
between braces. This type of syntax tells the computer that list is an integer array
with ten elements and it simultaneously assigns the ten provided values.
Chapter XI
The Array Data Structure
477