COP3252 Chapter 7 Flashcards

1
Q

Data Structures of Fixed Length

A

Array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Consider the array:

s[ 0 ] = 7
s[ 1 ] = 0
s[ 2 ] = -12
s[ 3 ] = 9
s[ 4 ] = 10
s[ 5 ] = 3
s[ 6 ] = 6

The value of s[ s[ 6 ] - s[ 5 ] ] is:

A

9

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

T or F

An array must be declared and then created before being used.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the following statement do?

double[] array = new double[14];

A

This creates a 14 element array of doubles

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Attempting to access an array element out of the bounds of an array, causes a(n)

ArrayElementOutOfBoundsException

ArrayOutOfBoundsException

ArrayException

ArrayIndexOutOfBoundsException

A

ArrayIndexOutofBoundException

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

T or F

The following statement creates an array of book objects.

new Book() books[];
books = new Book[ numberElements ];
A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

T or F

The following statement creates an array of book objects.

Book[] books;
books = new Book[ numberElements ];

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Consider the program below:

public class Test
{
   public static void main( String[] args )
   {
      int[] a;
      a = new int[ 10 ];
      for ( int i = 0; i < a.length; i++ )
         a[ i ] = i + 2;
      int result = 0;
      for ( int i = 0; i < a.length; i++ )
         result += a[ i ];
      System.out.printf( "Result is: %d\n", result );
   } // end main
} // end class Test

The output of this program will be:

A

65

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which statement correctly passes the array items to method takeArray? Array items contains 10 elements.

takeArray(items[10])
takeArray( items[])
takeArray( items )
takeArray( items[ 9 ] )

A

takeArray( items )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The preferred way to traverse a two-dimensional array is to use

A

two nested for loops

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
Which function is used to convert a string variable to integer?
convert.toInt(variable);
convert.partInt(variable);
variable.parseInt();
Integer.parseInt(variable);
A

Integer.parseInt(variable);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Lists and tables of values can be stored in which data structures?

A

arrays and collections

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

A collection of variables of the same data type stored contiguously in memory

A

Array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does an enhanced for statement do?

A

it allows you to iterate through an array without a counter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

the number used to refer to a particular element of an array is a…

A

index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What type of array has two indices?

A

a 2 dimensional array

17
Q

Which statement iterates through an array of doubles called numbers.

foreach (double:numbers);
for(double d:numbers);
while(double d :numbers: d++);
for(number n:numbers);

A

for(double d:numbers);

18
Q

Command line arguments are stored in ____________

A

an array of strings called args

19
Q

Use the expression ___________ to receive the total number of arguments in a command line. Assume that command-line arguments are stored in String[] args.

A

args.length

20
Q

Given the command java MyClass test, the first command-line argument is

21
Q

An _____________ in the parameter list of a method indicates that the method can receive a variable number of arguments.

A

… (ellipse)