Tuesday, 16 December 2014

// The "MDArrayExample7" class.  Page 323-324.
// (from the Carter book)
//
// Example 7:
//
// 1. These declarations are NOT VALID (see below):

public class MDArrayExample7
{
    public static void main (String[] args)
    {
        // (7a): (the first dimension is not specified):
        float[] [] badOne = new float[] [60];
        // (7b): (the second dimension (of 3) is not specified):
        boolean[] [] [] badTwo = new boolean [10] [] [25];
        // (see below for NOTES)

    } // main method
} // MDArrayExample7 class
//
// Example 7: (continued) --> NOTES:
//
// (7a):  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.
// (7b):  Although the first dimension has been specified here, the second
// and third dimensions show the same pattern that was exhibited in the "badOne"
// array declaration (in 7a).
//
// 2. Finally, we note that, just as one-dimensional array references can be
// used as parameters and return values of arrays from methods, so too can
// multi-dimensional array references.  Of course, the dimensions of arguments
// and parameters must match and their types must be appropriate.  It is also
// possible to pass sub-arrays as arguments to methods, as seen in the next
// example (8).

No comments:

Post a Comment