2-Dimensional Arrays

advertisement
2-Dimensional Arrays
One-Dimensional Array
• The array elements are selected using a one index
Two-Dimensional Array
• A two-dimensional array has two indices.
Defining a 2-Dimensional Array
1. Define an array object reference variable
double[][] a;
2. Create the array and store the location of the first element of
the array in the (array) object reference variable
a = new double[3][4]
Defining an initialized 2-dim. array:
Accessing elements of a 2dimensional array
Traversing (visiting) all elements in a
2-dimensional array
• We can use the following nest for-loop to visit all elements:
Using 2-dimensional arrays --manipulating pictures
• This coordinate system is the same one used for the Canvas
program
Manipulating Pictures (1)
• The picture consists of many number of (rows of) dots:
• A dot is called a pixel.
• Each pixel has a color...
Download