517
11.Using the declarations and array contents of Exercise 9 and the new values
stored in Exercise 10, show the contents of the array sampleafter the following
code segment executes.
for(k = 0 ; k < 8 ; k++)
if(k % 2 == 0 )
sample[k] = k;
else
sample[k] = k + 100 ;
12.What are the two basic differences between a class and an array?
13.If an array is passed as an argument, can the method change the array?
14.For each of the following descriptions of data, determine which general type of
data structure (array of primitive values, class, array of class objects, class con-
taining class objects ) is appropriate.
a.A payroll entry with a name, address, and pay rate
b.A person’s address
c. An inventory entry for a part
d.A list of addresses
e.A list of hourly temperatures
f. A list of passengers on an airliner, including names, addresses, fare classes,
and seat assignments
g.A departmental telephone directory with last name and extension number
15.What happens in Java if you try to access an element that is outside the extent
of the array?
16.To what are the array components initialized when you instantiate an array
usingnew?
17.To what are the array components initialized when you instantiate an array
using an initializer list?
Programming Warm-Up Exercises
Use the following declarations in Exercises 1–7. You may declare any other variables
that you need.
public classGrades
{
final intNUM_STUDENTS = 100 ; // Number of students