// (from the Carter book)
// Example 7:
// The following declarations are NOT legal. See the notes
// below the declarations for clarification:
public class MultiDimensionalArraysExample7
{
public static void main (String[] args)
{
// 7(a): a 2-dimensional array of x * 50 float numbers.
// (the first dimension is unspecified, but is needed.
float[] [] badOne = new float[] [50];
//
// 7(b): a 3-dimensional array of 10 * x * 25 boolean values.
// (the second dimension is unspecified, but is also required
// when the first dimension is specified; the third dimension
// does not have to be specified, however, in a 3-D array).
boolean[] [] [] badTwo = new boolean [10] [] [25];
//
// 7(a): Note: This attempt to create an unspecified number of arrays
// that are each of type float[50] will fail. The first
// dimension must always be specified.
//
// 7(b): Note2: Although the first dimension has been specified here,
// the second and third dimension show the same pattern
// that was exhibited in the "badOne" array declaration
// (see 7(a) above).
//
// Finally, we note that, just as one-dimensional array references can
// be used as parameters (passed to methods) and return values from methods,
// so too can multi-dimensional array references. Of course, the dimensions
// of arguments must match the parameters they are being passed to, and their
// types must also be appropriate. It is also possible to pass sub-arrays
// (partially-filled arrays) to methods, as Example 8 will show.
} // main method
} // MultiDimensionalArraysExample7 class
No comments:
Post a Comment