Archive for February 19, 2008

Chapter 9, 9.7

1. What are two-dimesional arrays?

– One array with each element is defined by two numbers.

2. Describe an application in which a two-dimensional array might be used.

– To create a table with numerator and denominator.

3.

– for (row=0; row < table.length; row ++)

for (col = 0; table[row]. length; col++)

if (table[row][col] <0)

break;
4. Describe the contents of the array after the following code segment is run:

– It creates a five by five table and assign a value of the product of rows and colums into each spot.

Chapter 9, 9.6

1. What are parallel arrays?– They are arrays that contains corresponding data in cells of same index. 2. Describe an application in which parallel arrays might be used.– The declaration between people’s name and their age in the school. 3. Declare an instantiate the variables for parallel arrays to track the names, ages, and social security numbers of 50 employees.String [] name = new String[50]int [] age = new int [50]int [] security = new int [50]String searchPerson;int correspondingAge = -1, correspondingSecurity = -1searchName = …for (int i = 0, i<name.length; i ++) if (searchName.equal (name[i]))correspondingAge = age [i]correpondingSecurity = security [i]break;}. 5. Write a code segment that creates parallel arrays containing the first 10 nonnegative powers of 2. One array should contain the exponent and the other array should contain 2 raised to that power.

– int[] exponent = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

int[] powers = new int[10];

for (int i = 0; int < 10; i++){

power [i] = math.pow(2, exponent[i])

} ;

Chapter 9, 9.5

1. What happens when the programmer tries to access an array cell whose index is greater than or equal to its logical size? — It will give you the default value of zero, and to add another value we just need to expand the size of of the logical size. 2. Describe an application that uses an array that might not be full. — For example, create a class with 5 kids in the class and leave some spaces for upcoming students.