Wednesday, 17 December 2014

// The "TablesAndArraysExample1" class.  Page 309.
// (from the Carter book)

// Example 1:

// The temperatures of a solution over a 6-minute interval
// are recorded in the following table:
// Time (min.)  0       1       2       3       4       5       6
// Temp.(deg.C) 32.0    27.2    24.4    22.7    21.6    21.0    20.6
//
// An array "temp" could be used to record the temperatures of a solution
// each minute, as follows:
// 1. The identifier of the array is "temp".
// 2. The identifiers of the elements are: temp[0], temp[1],...temp[6].
// 3. The values of the elements are 32.0, 27.4,....20.6.
// 4. The indices of the elements are 0, 1, 2,...6.

public class TablesAndArraysExample1
{
    public static void main (String[] args)
    {
        // to declare an array called "temp" of type double:
        double[] temp;
        // to create an array called "temp" with 6 elements:
        temp = new double [6];  // temp[0] does not have to be used
        // or, combine the declaration and creation of the "temp" array
        // of type double:
        double[] temp = new double [6];
        // the declaration and creation of the "temp" array makes
        // enough space in memory for 6 double numbers.

    } // main method
} // TablesAndArraysExample1 class

No comments:

Post a Comment