Wednesday, 17 December 2014

// The "TablesAndArraysExample2" class.  Page 310.
// (from the Carter book)

// Example 2:

// The following fragment declares an int array
// called "list" of size 20.
//
// 1. Once an array has been declared, its size is fixed
// for the duration of its existence.
// 2. Every array object has a 'length' field whose value
// can be obtained by appending '.length' to the array's
// identifier --> <identifier>.length will tell you how
// long the array is.
// 3. Since arrays are always indexed from 0, the length
// of an array is one longer than the highest index
// in the array.

public class TablesAndArraysExample2
{
    public static void main (String[] args)
    {
        // int types include: byte, short, long, as well as int
        byte b = 10;
        // the array called "list" has 2 * 10 (or 20 elements)
        // since b == 10 and 2 * b = 20.
        int[] list = new int [2 * b];

    } // main method
} // TablesAndArraysExample2 class

No comments:

Post a Comment