Self-Review Exercises

E.1 Fill in the blank(s) in each of the following statements:

a) Lists and tables of values can be stored in _________.

b) An array is a group of _________ (called elements or components) containing values that all have the same _________.

c) The _________ allows you to iterate through the elements in an array without using a counter.

d) The number used to refer to a particular array element is called the element’s _________.

e) An array that uses two indices is referred to as a(n) _________ array.

f) Use the enhanced for statement _________ to walk through double array numbers.

g) Command-line arguments are stored in _________.

E.2 Determine whether each of the following is true or false. If false, explain why.

a) An array can store many different types of values.

b) An array index should normally be of type float.

c) An individual array element that’s passed to a method and modified in that method will contain the modified value when the called method completes execution.

E.3 Perform the following tasks for an array called fractions:

a) Declare a constant ARRAY_SIZE that’s initialized to 10.

b) Declare an array with ARRAY_SIZE elements of type double, and initialize the elements to 0.

c) Refer to array element 4.

d) Assign the value 1.667 to array element 9.

e) Assign the value 3.333 to array element 6.

f) Sum all the elements of the array, using a for statement. Declare the integer variable x as a control variable for the loop.

E.4 Perform the following tasks for an array called table:

a) Declare and create the array as an integer array that has three rows and three columns. Assume that the constant ARRAY_SIZE has been declared to be 3.

b) How many elements does the array contain?

c) Use a for statement to initialize each element of the array to the sum of its indices. Assume that the integer variables x and y are declared as control variables.

E.5 Find and correct the error in each of the following program segments:

a) final int ARRAY_SIZE = 5 ;

    ARRAY_SIZE = 10 ;

b) Assume int[] b = new int[ 10 ];

    for ( int i = 0 ; i <= b.length; i++ )

            b[ i ] = 1 ;

c) Assume int[][] a = { { 1 , 2 }, { 3 , 4 } };

         a[ 1 , 1 ] = 5 ;

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset