Java Ch. 7 Quiz

Your page rank:

Total word count: 1430
Pages: 5

Calculate the Price

- -
275 words
Looking for Expert Opinion?
Let us have a look at your work and suggest how to improve it!
Get a Consultant

What does the following statement do?

double[] array1 = new double[10];

a. Declares array1 to be a reference to an array of double values
b. Creates an instance of an array of 10 double values
c. Will allow valid subscripts in the range of 0 – 9
d. All of these

d. All of these

To return an array of long values from a method, use this as the return type for the method.

a. long[ARRAY_SIZE]
b. long[]
c. long
d. []long

b. long[]

It is common practice to use a ________ variable as a size declarator.

a. final
b. static
c. reference
d. boolean

a. final

If numbers is a two-dimensional array, which of the following would give the length of row r?

a. numbers[r].length[r]
b. numbers.length
c. numbers.length[r]
d. numbers[r].length

d. numbers[r].length

Subscript numbering always starts at what value?

a. 0
b. 1
c. -1
d. None of these

a. 0

What do you call the number that is used as an index to pinpoint a specific element within an array?

a. global unique identifier
b. element
c. subscript
d. argument

c. subscript

Java performs ________, which means that it does not allow a statement to use a subscript that is outside the range of valid subscripts for the array.

a. active array sequencing
b. buffer overrun protection
c. array bounds checking
d. scope resolution binding

c. array bounds checking

The following statement creates an ArrayList object. What is the purpose of the <String> notation?

ArrayList<String> arr = new ArrayList<String>();

a. It specifies that String objects may not be stored in the ArrayList object.
b. It specifies that the get method will return only String objects.
c. It specifies that everything stored in the ArrayList object will be converted to a String.
d. It specifies that only String objects may be stored in the ArrayList object.

d. It specifies that only String objects may be stored in the ArrayList object.

What will be returned from the following method?

public static float[] getValue(int x)

a. An array of float values
b. An array of integers
c. A float value
d. An integer

a. An array of float values

For the following code, what would be the value of str[2]?

String[] str = {"abc", "def", "ghi", "jkl"};

a. A reference to the String "def"
b. A reference to the String "ghi"
c. "def"
d. "ghi"

b. A reference to the String "ghi"

In order to do a binary search on an array:

a. the values of the array must be numeric
b. the array must first be sorted in ascending order
c. you must first do a sequential search of the array to assure the element you are looking for is there
d. there are no requirements

b. the array must first be sorted in ascending order

In Java, you do not use the new operator when you use a(n):

a. array size declarator
b. initialization list
c. two-dimensional array
d. All of these

b. initialization list

This indicates the number of elements, or values, the array can hold.

a. the array’s data type
b. the array’s size declarator
c. the new operator
d. the version of Java

b. the array’s size declarator

What will be the result of executing the following code?

int[] x = {0, 1, 2, 3, 4, 5};

a. The program will crash when it is executed.
b. A compilation error will occur.
c. An array of 6 values ranging from 0 through 5 and referenced by the variable x will be created.
d. The value of x[1] will be 0, x[2] will be 0, x[3] will be 0, x[4] will be 0, x[5] will be 0, and x[6] will be 0.

c. An array of 6 values ranging from 0 through 5 and referenced by the variable x will be created.

What is the value of scores[2][3] in the following array?

int [][] scores = { {88, 80, 79, 92}, {75, 84, 93, 80}, {98, 95, 92, 94}, {91, 84, 88, 96} };

a. 84
b. 94
c. 95
d. 93

b. 94

Given that String[] str has been initialized, to get a copy of str[0] with all characters converted to upper case, use the following statement:

a. str[0].upperCase();
b. str.toUpperCase();
c. str[0].toUpperCase();
d. str.uppercase();

c. str[0].toUpperCase();

The binary search algorithm:

a. will cut the portion of the array being searched in half each time the loop fails to locate the search value
b. will have an average of N/2 comparisons, where N is the number of elements in the array
c. is less efficient than the sequential search algorithm
d. will have a maximum number of comparisons equal to the number of elements in the array

a. will cut the portion of the array being searched in half each time the loop fails to locate the search value

This ArrayList class method deletes an item from an ArrayList.

a. erase
b. remove
c. purge
d. delete

b. remove

Given the following two-dimensional array declaration, which statement is TRUE?

int [][] numbers = new int [6] [9];

a. The array numbers has 54 rows.
b. The array numbers has 6 columns and 9 rows.
c. The array numbers has 15 rows.
d. The array numbers has 6 rows and 9 columns.

d. The array numbers has 6 rows and 9 columns.

Each array in Java has a public field named ________ that contains the number of elements in the array.

a. capacity
b. limit
c. size
d. length

d. length

The ArrayList class is in this package.

a. java.arraylist
b. java.util
c. java.lang
d. java.array

b. java.util

The sequential search algorithm:

a. must always be implemented as a method
b. uses a loop to sequentially step through an array, starting with the first element
c. requires the array to be ordered
d. will not execute, if the element is not in the array

b. uses a loop to sequentially step through an array, starting with the first element

A search algorithm:

a. arranges elements in descending order
b. is a way to locate a specific item in a larger collection of data
c. is rarely used with arrays
d. arranges elements in ascending order

b. is a way to locate a specific item in a larger collection of data

By default, Java initializes array elements with what value?

a. 0
b. 1
c. 100
d. -1

a. 0

What do you normally use with a partially-filled array?

a. A class that does nothing but manage the array
b. An accompanying parallel array
c. An accumulator
d. An accompanying integer value that holds the number of items stored in the array

d. An accompanying integer value that holds the number of items stored in the array

If numbers is a two-dimensional int array that has been initialized and total is an int that has been set to 0, which of the following will sum all the elements in the array?

a. for (int row = 1; row < numbers.length; row++)
{
for (int col = 1; col < numbers.length; col++)
total += numbers [row][col];

b. for (int row = 0; row < numbers.length; row++)
{
for int col = 0; col < numbers[row].length; col++)
total += numbers[row][col];
}

c. for (int for = 0; numbers.length; row++)
{
for (int col = 0; col < numbers.length; col++)
total += numbers[row][col];
}

d. for (int row = 0; row < numbers[row].length; row++)
{
for (int col = 0; col < numbers.length; col++)
total += numbers[row][col];
}

b. for (int row = 0; row < numbers.length; row++) { for int col = 0; col < numbers[row].length; col++) total += numbers[row][col]; }

A ragged array is:

a. a two-dimensional array for which the number of rows is unknown
b. a one-dimensional array for which the number of elements is unknown
c. a two-dimensional array where the rows are of different lengths
d. There is no such thing as a ragged array

c. a two-dimensional array where the rows are of different lengths

If final int SIZE = 15 and int[] x = new int[SIZE], what would be the range of subscript values that could be used with x[]?

a. 1 through 14
b. 1 through 15
c. 0 through 15
d. 0 through 14

d. 0 through 14

This ArrayList class method is used to insert an item into an ArrayList.

a. store
b. insert
c. putItem
d. add

d. add

In memory, an array of String objects:

a. consists of elements, each of which is a String object
b. must be initialized when the array is declared
c. is always implemented as a ragged array
d. consists of elements, each of which is a reference to a String object

d. consists of elements, each of which is a reference to a String object

Share This
Flashcard

More flashcards like this

NCLEX 10000 Integumentary Disorders

When assessing a client with partial-thickness burns over 60% of the body, which finding should the nurse report immediately? a) ...

Read more

NCLEX 300-NEURO

A client with amyotrophic lateral sclerosis (ALS) tells the nurse, "Sometimes I feel so frustrated. I can’t do anything without ...

Read more

NASM Flashcards

Which of the following is the process of getting oxygen from the environment to the tissues of the body? Diffusion ...

Read more

Unfinished tasks keep piling up?

Let us complete them for you. Quickly and professionally.

Check Price

Successful message
sending