revised: 05/01/2006


Quiz on Arrays

Instructions: For each question, choose the single best answer. Make your choice by clicking on its button. You can change your answers at any time. When the quiz is graded, the correct answers will appear in the box after each question.



1. Which of the following declares a reference to an array of int named img?

A.    int img;
B.    int[] img;
C.    new int img[];
D.    int img = int[];

2. What is the output of the following code fragment:

int[] ar = {2, 4, 6, 8 };
System.out.println( ar[0] + " " + ar[1] );

A.    2 6
B.    8
C.    2 4
D.    6 8

3. What is the output of the following code fragment:

int[] y = new int[10];

y[0] = 34;
y[1] = 88;

System.out.println( y[0] + " " + y[1] + " " + y[5] );

A.    34 88 0
B.    34 88 88
C.    The program is defective and will not compile.
D.    0 34 88

4. What is the output of the following code fragment:

int[] zip = new int[5];

zip[0] = 7;
zip[1] = 3;
zip[2] = 4;
zip[3] = 1;
zip[4] = 9;

System.out.println( zip[ 2 + 1 ] );

A.    4 3
B.    3 7
C.    1
D.    9

5. How many objects are present after the following code fragment has executed?

double[] ann = new double[ 7 ];
double[] bob;

bob = ann;

A.    2
B.    1
C.    14
D.    7

6. What is the output of the following code fragment:

int[] z = new int[9];

z[0] = 7;
z[1] = 3;
z[2] = 4;

System.out.println( (z[0] + z[1]) + " " + z[5] );

A.    7 3 0
B.    10 0
C.    7 3 4
D.    10 5

7. What is the output of the following code fragment:

int[] zip = new int[5];

zip[0] = 7;
zip[1] = 3;
zip[2] = 4;
zip[3] = 1;
zip[4] = 9;

System.out.println( zip[ 4 ]/zip[ 1 ] );

A.    1
B.    3
C.    7
D.    9

8. What is the output of the following code fragment:

int[] zip = new int[5];

zip[0] = 7;
zip[1] = 3;
zip[2] = 4;
zip[3] = 1;
zip[4] = 9;

int j = zip[1];

System.out.println( zip[ j+1 ] );

A.    1
B.    3
C.    7
D.    9

9. What is the output of the following code fragment:

int[] data = {0, 3, 7, 9, 12, 14};

System.out.println( data[ data[1] ] );

A.    0
B.    3
C.    7
D.    9
E.    12
F.    14

10. For which of the following applications is an array NOT suitable:

A.    Holding the scores on twelve midterms exams of a class.
B.    Holding the name, social security number, age, and income of one individual.
C.    Holding the temperature readings taken every hour throughout a day.
D.    Holding the total sales a store made in each of twelve months.

The number you got right:       Percent Correct:       Letter Grade:   


Click here

If you have returned here from another page, or have re-loaded this page, you will need to click again on each of your choices for the grading program to work correctly. You may want to press the SHIFT KEY while clicking to clear the old answers.