created 12/05/99

Quiz on 2D 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. Examine the following:

double[][] values =
  { {1.2, 9.0, 3.2},
    {9.2, 0.5, 1.5, -1.2},
    {7.3, 7.9, 4.8} } ;

what is in   values[2][1] ?

a.    7.3
b.    7.9
c.    9.2
d.    There is no such array element.

Correct Answer Is:


2. Examine the following:

double[][] values =
  { {1.2, 9.0, 3.2},
    {9.2, 0.5, 1.5, -1.2},
    {7.3, 7.9, 4.8} } ;

what is in   values[3][0] ?

a.    7.3
b.    7.9
c.    9.2
d.    There is no such array element.

Correct Answer Is:


3. You want to create a table that looks like:

12-98
714
-32-10

Which of the following will work?


a.   
double[][]  table =
  { 12, -9, 8,
    7, 14,
    -32, -1, 0} ;
b.   
double[][] table =
  { {12, -9, 8},
    {7, 14, 0},
    -32, -1, 0} };
c.   
double[][] table =
  { {12, -9, 8}
    {7, 14}
    {-32, -1, 0} };
d.   
double[][] table =
  { {12, -9, 8},
    {7, 14},
    {-32, -1, 0} };

Correct Answer Is:


4. Given the following:

double[][] things =
  { {1.2, 9.0},
    {9.2, 0.5, 0.0},
    {7.3, 7.9, 1.2, 3.9} } ;

What is the value of things.length ?

a.    2
b.    3
c.    4
d.    9

Correct Answer Is:


5. Given the following:

double[][] things =
  { {1.2, 9.0},
    {9.2, 0.5, 0.0},
    {7.3, 7.9, 1.2, 3.9} } ;

What is the value of things[2].length ?

a.    2
b.    3
c.    4
d.    9

Correct Answer Is:


6. Given the following:

long[][] stuff ;

Which of the following statements constructs an array with 5 rows of 7 columns each and assign its reference to stuff ?

a.    stuff = new stuff[5][7] ;
b.    stuff = new long[5][7] ;
c.    stuff = long[5][7] ;
d.    stuff = long[7][5] ;

Correct Answer Is:


7. Given the following:

int[][] items =
  { {0, 1, 3, 4},
    {4, 3, 99, 0, 7 },
    {3, 2} } ;

Which of the following statements replaces the 99 with 77?

a.    items[1][2] = 77;
b.    items[2][1] = 77;
c.    items[ 99 ] = 77;
d.    items[2][3] = 77;

Correct Answer Is:


8. Which of the following constructs and assigns to array a 2D array with 7 rows, but does not yet construct the rows?

a.    int[][] array = new int[7][];
b.    int[][] array = new int[7];
c.    int[][] array = new int[][7];
d.    int[] array[7] = new int[];

Correct Answer Is:


9. Given:

int[][] items =
  { {0, 1, 3, 4},
    {4, 3, 99, 0, 7 },
    {3, 2} } ;

Which of the following fragments prints out every element of items?

a.   
for ( int row=0; row < items.length; row++ )
{
  System.out.println();
  for ( int col=0; col < items.length; col++ )
    System.out.print( items[row][col] + " ");
}
b.   
for ( int row=0; row < items.length; row++ )
{
  System.out.println();
  for ( int col=0; col < items[col].length; col++ )
    System.out.print( items[row][col] + " ");
}
c.   
for ( int row=0; row < items.length; row++ )
{
  System.out.println();
  for ( int col=0; col < items[row].length; col++ )
    System.out.print( items[row][col] + " ");
}
d.   
for ( int row=0; row < items.length; row++ )
{
  for ( int row=0; row < items[row].length; row++ )
    System.out.print( items[row][col] + " ");
  System.out.println();
}

Correct Answer Is:


10. Given:

int[][] items =
  { {0, 1, 3, 4},
    {4, 3, 99, 0, 7 },
    {3, 2} } ;

Which of the following fragments replaces row 0 of items with an entierly new row?

a.   
items[0][0] = 8;
items[0][1] = 12;
items[0][2] = 6;
b.   
items[0] = { 8, 12, 6 };
c.   
items[0] = new { 8, 12, 6 };
d.   
int[] temp = { 8, 12, 6 };
items[0] = temp;

Correct Answer Is:


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.)