Summary: This section describes the meaning of the array, the three steps to create the array, the typical array processing code, the aliases, and the contents of the two-dimensional array.
Focus:
1. When creating an array, you need to specify the length of the array (the number of elements). The reason we need to explicitly create an array at run time is because the Java compiler does not know at compile time how much space should be reserved for the array (which is possible for the original type).
2.
Doublenewdouble[N]; for (int i = 0; i < N; i++) = 0.0;
The For statement initializes the n elements of the array, placing their values at 0.0. When using arrays in your code, be sure to declare, create, and initialize the array in turn. Ignoring any of these steps is a common programming error.
However, the for statement does not need to be initialized in the actual test.
3.Java automatically checks for bounds-if you create an array of size n, but use an index that is less than 0 or greater than N-1 to access it, the program terminates because the runtime throws an Arrayoutofboundsexception exception.
4. Familiarize yourself with the typical array processing code (P11-P12):
· Find the largest element in an array
· Computes the average of an array element
· Copying an array
· Reverse the order of array elements
· Matrix multiplication (Phalanx)-a[][] * b[][] = c[][]
5. The array name represents the entire array-if we assign an array variable to another variable, then two variables will point to the same array. If you want to copy an array, you should declare, create, and initialize a new array, and then copy the element values from the original array to the new array, as shown in the third example above.
6. When creating a two-dimensional array, specify the number of rows and the number of columns in square brackets after the type name, for example:
Double New Double M [N];
Algorithm (4th edition) -1.1.5 array