Quiz on Arrays

This is a practice quiz. The results are not recorded anywhere and do not affect your grade. The questions on this quiz might not appear in any quiz or test that does count toward your grade.

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 an array of int named img?

Correct Answer Is:

a. int img;
b. int[] img;
c. new int img[];
d. int img = int[];

2. What are the legal indexes for the array ar, given the following declaration:

int[] ar = {2, 4, 6, 8 }

Correct Answer Is:

a. 0, 1, 2, 3
b. 1, 2, 3, 4
c. 2, 4, 6, 8
d. 0, 2, 4. 6

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

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

Correct Answer Is:

a. 2 6
b. 8
c. 2 4
d. 6 8

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

int[] ar = {2, 4, 6, 8 };

ar[0] = 23;
ar[3] = ar[1];

System.out.println( ar[0] + " " + ar[3] );

Correct Answer Is:

a. 23 2
b. 2 8
c. 31
d. 23 4

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

int[] y = new int[5];

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

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

Correct Answer Is:

a. 34 88 0
b. 34 88 88
c. The program is defective and will not compile.
d. 0 34 88

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] );

Correct Answer Is:

a. 10 0
b. 7 3 0
c. The program is defective and will not compile.
d. 7 3 4

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[ 2 + 1 ] );

Correct Answer Is:

a. 4 3
b. 3 7
c. 4
d. 1

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 = 3;

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

Correct Answer Is:

a. 7
b. 3
c. 4
d. 1

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

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

bob = ann;

Correct Answer Is:

a. 2
b. 7
c. 14
d. 1

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

Correct Answer Is:

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 just 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 on reload to clear the old answers.)