COP3252 Chapter 7 Flashcards
Data Structures of Fixed Length
Array
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:
9
T or F
An array must be declared and then created before being used.
True
What does the following statement do?
double[] array = new double[14];
This creates a 14 element array of doubles
Attempting to access an array element out of the bounds of an array, causes a(n)
ArrayElementOutOfBoundsException
ArrayOutOfBoundsException
ArrayException
ArrayIndexOutOfBoundsException
ArrayIndexOutofBoundException
T or F
The following statement creates an array of book objects.
new Book() books[]; books = new Book[ numberElements ];
False
T or F
The following statement creates an array of book objects.
Book[] books;
books = new Book[ numberElements ];
True
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:
65
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 ] )
takeArray( items )
The preferred way to traverse a two-dimensional array is to use
two nested for loops
Which function is used to convert a string variable to integer? convert.toInt(variable); convert.partInt(variable); variable.parseInt(); Integer.parseInt(variable);
Integer.parseInt(variable);
Lists and tables of values can be stored in which data structures?
arrays and collections
A collection of variables of the same data type stored contiguously in memory
Array
What does an enhanced for statement do?
it allows you to iterate through an array without a counter
the number used to refer to a particular element of an array is a…
index
What type of array has two indices?
a 2 dimensional array
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);
for(double d:numbers);
Command line arguments are stored in ____________
an array of strings called args
Use the expression ___________ to receive the total number of arguments in a command line. Assume that command-line arguments are stored in String[] args.
args.length
Given the command java MyClass test, the first command-line argument is
test
An _____________ in the parameter list of a method indicates that the method can receive a variable number of arguments.
… (ellipse)