Quiz 9
Version 1

 

 

Zap

Quiz for CS 5
Week 9

0. What's wrong with your program if it produces this error message when you try to run it:

java.lang.ArrayIndexOutOfBoundsException 

1. What is the difference between the declaration:

int[] fred, alice, suzie; 
and the declaration:
int fred[], alice, suzie; 

2. Maxwell declared times to be an array of doubles using:

double[] times; 
and then followed this immediately with the line:
times[4] = 5; 
What did he forget to do?

3. What is the index of the first element of an array? The third element?

4. What is a fence-post error?

5. How would you find out the number of elements of an array named idnums?

6. Give the header of a for loop designed to enumerate all the elements of the array idnums?

7. In order to use binary search to find a value in an array, the data in the array must have a particular property. What is it?

8. Suppose that phvals is declared as an array of doubles. What happens if you try to allocate it using the statement phvals = new double[Math.PI];?

9. Marcia declared an array of 15 ints, named sprockets using the line:

int sprockets[] = new int[15]; 
She then attempted to initialize the array as follows:
for (int i = 1 ; i <= 15 ; i++) {
   sprockets[i]=23;
} 
Why didn't this work?

10. It takes a bit longer to access an array element in Java than it does in C. Why? What benefit do you get in return for this decrease in speed?

Last modified August 28 for Fall 99 cs5 by fleck@cs.hmc.edu


This page copyright ©1998 by Joshua S. Hodas. It was built with Frontier on a Macintosh . Last rebuilt on Tue, Oct 20, 1998 at 8:40:54 PM.
http://www.cs.hmc.edu/~hodas/courses/cs5/week_09/quiz.html