Deck 7: Arrays and Array Lists
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/117
Play
Full screen (f)
Deck 7: Arrays and Array Lists
1
What is the result of executing this code snippet?
A)The code snippet does not give any output.
B)The code snippet displays all the marks stored in the array without any redundancy.
C)The code snippet causes a bounds error.
D)The code snippet executes an infinite loop.

A)The code snippet does not give any output.
B)The code snippet displays all the marks stored in the array without any redundancy.
C)The code snippet causes a bounds error.
D)The code snippet executes an infinite loop.
The code snippet causes a bounds error.
2
Which statements about the enhanced for loop are true for arrays of primitive data?
I.It is suitable for all array algorithms.
II.It does not allow the contents of the array to be modified.
III.It does not require the use of an index variable.
A)I, II only
B)I, III only
C)II, III only
D)I, II, III
I.It is suitable for all array algorithms.
II.It does not allow the contents of the array to be modified.
III.It does not require the use of an index variable.
A)I, II only
B)I, III only
C)II, III only
D)I, II, III
II, III only
3
Identify the correct statement for defining an integer array named numarray of ten elements.
A)int[] numarray = new int[9];
B)int[] numarray = new int[10];
C)int[10] numarray;
D)int numarray[10];
A)int[] numarray = new int[9];
B)int[] numarray = new int[10];
C)int[10] numarray;
D)int numarray[10];
int[] numarray = new int[10];
4
In a partially filled array, the number of slots in the array that are not currently used is the
A)length of the array minus the number of elements currently in the array.
B)number of elements currently in the array minus the length of the array.
C)length of the array plus the number of elements currently in the array.
D)number of elements currently in the array.
A)length of the array minus the number of elements currently in the array.
B)number of elements currently in the array minus the length of the array.
C)length of the array plus the number of elements currently in the array.
D)number of elements currently in the array.
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
5
Which one of the following statements is correct for the given code snippet?
A)Line 2 declares and initializes an array of three elements with value 5.
B)Line 2 causes a bounds error because 3 is an invalid index number.
C)Line 2 initializes the third element of the array with value 5.
D)Line 2 initializes all the elements of the array with value 5.

A)Line 2 declares and initializes an array of three elements with value 5.
B)Line 2 causes a bounds error because 3 is an invalid index number.
C)Line 2 initializes the third element of the array with value 5.
D)Line 2 initializes all the elements of the array with value 5.
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
6
If currLength is an integer variable that gives the number of elements currently in the array myArray, which code snippet prints out the elements in the partially filled array of integers?
A)
B)
C)
D)
A)

B)

C)

D)

Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
7
When a Java program terminates and reports an exception, the error message contains which pieces of useful information?
I.the compile and revision control history of the source code changes that caused the error
II.the name of the exception that occurred
III.the stack trace
A)I, II only
B)I, III only
C)II, III only
D)I, II, III
I.the compile and revision control history of the source code changes that caused the error
II.the name of the exception that occurred
III.the stack trace
A)I, II only
B)I, III only
C)II, III only
D)I, II, III
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
8
The enhanced for loop is
A)convenient for traversing all elements in an array.
B)convenient for traversing elements in a partially filled array.
C)only used for arrays of integers.
D)used to initialize all array elements to a common value.
A)convenient for traversing all elements in an array.
B)convenient for traversing elements in a partially filled array.
C)only used for arrays of integers.
D)used to initialize all array elements to a common value.
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
9
What is the result of the following code?
A)The elements of the array values are initialized to zero.
B)The elements of the array element are initialized to zero.
C)The first element of the array values is initialized to zero.
D)The array values is not modified.

A)The elements of the array values are initialized to zero.
B)The elements of the array element are initialized to zero.
C)The first element of the array values is initialized to zero.
D)The array values is not modified.
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
10
Consider the following line of code:
int[] somearray = new int[30];
Which one of the following options is a valid line of code for displaying the twenty-eighth element of somearray?
A)System.out.println(somearray[28]);
B)System.out.println(somearray(28));
C)System.out.println(somearray(27));
D)System.out.println(somearray[27]);
int[] somearray = new int[30];
Which one of the following options is a valid line of code for displaying the twenty-eighth element of somearray?
A)System.out.println(somearray[28]);
B)System.out.println(somearray(28));
C)System.out.println(somearray(27));
D)System.out.println(somearray[27]);
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
11
When an array myArray is only partially filled, how can the programmer keep track of the current number of elements?
A)access myArray.length()
B)maintain a companion variable that stores the current number of elements
C)access myArray.currentElements()
D)access myArray.length() - 1
A)access myArray.length()
B)maintain a companion variable that stores the current number of elements
C)access myArray.currentElements()
D)access myArray.length() - 1
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
12
Which one of the following statements is true about using arrays with methods?
A)Arrays can be method arguments, and return values, just like any other values.
B)A method can only accept arguments that are elements of an array, but not the whole array.
C)A method may accept an argument that is an array, but it cannot return a result that is an array.
D)If a method is defined to have an array as a method argument, it must also define the size of the array as another method argument.
A)Arrays can be method arguments, and return values, just like any other values.
B)A method can only accept arguments that are elements of an array, but not the whole array.
C)A method may accept an argument that is an array, but it cannot return a result that is an array.
D)If a method is defined to have an array as a method argument, it must also define the size of the array as another method argument.
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
13
Which one of the following statements is correct about the given code snippet?
A)The for loop initializes all the elements of the array.
B)The for loop initializes all the elements except the first element.
C)The for loop initializes all the elements except the last element.
D)The for loop initializes all the elements except the first and last elements.

A)The for loop initializes all the elements of the array.
B)The for loop initializes all the elements except the first element.
C)The for loop initializes all the elements except the last element.
D)The for loop initializes all the elements except the first and last elements.
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
14
What is the output of the given code snippet?
A)2345
B)1234
C)1345
D)1111

A)2345
B)1234
C)1345
D)1111
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
15
What is the valid range of index values for an array of size 10?
A)0 to 9
B)0 to 10
C)1 to 9
D)1 to 10
A)0 to 9
B)0 to 10
C)1 to 9
D)1 to 10
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
16
What is the output of the following code snippet?
A)1050
B)2030
C)3040
D)4050

A)1050
B)2030
C)3040
D)4050
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
17
What is displayed after executing the given code snippet?
A)The code snippet displays the total marks of all ten subjects.
B)The for loop causes a run-time time error on the first iteration.
C)The code snippet causes a bounds error.
D)The code snippet displays zero.

A)The code snippet displays the total marks of all ten subjects.
B)The for loop causes a run-time time error on the first iteration.
C)The code snippet causes a bounds error.
D)The code snippet displays zero.
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
18
Complete the following code snippet with the correct enhanced for loop so it iterates over the array without using an index variable.
A)for (String str : arr)
B)for (str : String arr)
C)for (str[] : arr)
D)for (arr[] : str)
![<strong>Complete the following code snippet with the correct enhanced for loop so it iterates over the array without using an index variable. </strong> A)for (String str : arr) B)for (str : String arr) C)for (str[] : arr) D)for (arr[] : str)](https://d2lvgg3v3hfg70.cloudfront.net/TB7392/11eb9782_fd7b_226a_b9fe_67c5c3d9b93f_TB7392_00.jpg)
A)for (String str : arr)
B)for (str : String arr)
C)for (str[] : arr)
D)for (arr[] : str)
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
19
Which one of the following statements is a valid initialization of an array named somearray of ten elements?
A)int[] somearray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
B)int somearray[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
C)int[10] somearray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
D)int somearray[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
A)int[] somearray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
B)int somearray[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
C)int[10] somearray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
D)int somearray[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
20
Which statement correctly describes the enhanced for loop?
A)In the enhanced for loop, the element variable is assigned.In the basic for loop, the index variable is assigned.
B)In the enhanced for loop, the index variable is assigned.In the basic for loop, the element variable is assigned.
C)The enhanced for loop has a very specific purpose: modifying the contents of the array.
D)The enhanced for loop has a very specific purpose: initializing the contents of the array.
A)In the enhanced for loop, the element variable is assigned.In the basic for loop, the index variable is assigned.
B)In the enhanced for loop, the index variable is assigned.In the basic for loop, the element variable is assigned.
C)The enhanced for loop has a very specific purpose: modifying the contents of the array.
D)The enhanced for loop has a very specific purpose: initializing the contents of the array.
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
21
Consider the following code snippet in Java 6 or later:
What does the last element of data2 contain?
A)"abc"
B)"def"
C)"ghi"
D)"jkl"

A)"abc"
B)"def"
C)"ghi"
D)"jkl"
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
22
Assume the array of integers values has been created.Which condition must be used in the indicated area so the loop below will assign max the largest value in values?
A)max > val
B)val > max
C)values[val] > max
D)max > values[val]
![<strong>Assume the array of integers values has been created.Which condition must be used in the indicated area so the loop below will assign max the largest value in values? </strong> A)max > val B)val > max C)values[val] > max D)max > values[val]](https://d2lvgg3v3hfg70.cloudfront.net/TB7392/11eb9782_fd7b_e5bd_b9fe_ad1cfbc7fbfb_TB7392_00.jpg)
A)max > val
B)val > max
C)values[val] > max
D)max > values[val]
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
23
Consider the following code snippet:
String[] data = { "123", "ghi", "jkl", "def", "%&*" };
Which statement sorts the data array in ascending order?
A)data = Arrays.sort();
B)Arrays.sort(data);
C)data = Arrays.sort(data.length);
D)data = Arrays.sort(data);
String[] data = { "123", "ghi", "jkl", "def", "%&*" };
Which statement sorts the data array in ascending order?
A)data = Arrays.sort();
B)Arrays.sort(data);
C)data = Arrays.sort(data.length);
D)data = Arrays.sort(data);
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
24
What is the output of the following code snippet?
A)24 0 30 16
B)24 0 30 6
C)24 7 30 16
D)24 16 24 16

A)24 0 30 16
B)24 0 30 6
C)24 7 30 16
D)24 16 24 16
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
25
Assume the following variable has been declared and given a value as shown:
int[] numbers = {9, 17, -4, 21 };
Which is the value of numbers.length?
A)3
B)4
C)9
D)21
int[] numbers = {9, 17, -4, 21 };
Which is the value of numbers.length?
A)3
B)4
C)9
D)21
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
26
Consider the following code snippet:
String[] data = { "abc", "def", "ghi", "jkl" };
Using Java 6 or later, which statement grows the data array to twice its size?
A)data = Arrays.copyOf(data, 2 * data.length);
B)data = Arrays.copyOf(data, 2);
C)data = Arrays.copyOf(data, 2 * data);
D)data = Arrays.copyOf(data, 2 * data.size());
String[] data = { "abc", "def", "ghi", "jkl" };
Using Java 6 or later, which statement grows the data array to twice its size?
A)data = Arrays.copyOf(data, 2 * data.length);
B)data = Arrays.copyOf(data, 2);
C)data = Arrays.copyOf(data, 2 * data);
D)data = Arrays.copyOf(data, 2 * data.size());
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
27
When an array reading and storing input runs out of space
A)the program could be recompiled with a bigger size for the array.
B)the array could be "grown" using the growArray method.
C)it automatically resizes to accommodate new elements.
D)the array could be "grown" using the new command and the copyOf method.
A)the program could be recompiled with a bigger size for the array.
B)the array could be "grown" using the growArray method.
C)it automatically resizes to accommodate new elements.
D)the array could be "grown" using the new command and the copyOf method.
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
28
Which code snippet calculates the sum of all the elements in even positions in an array?
A)
B)
C)
D)
A)

B)

C)

D)

Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
29
What (if anything) is wrong with the following code snippet, which searches for the searchedValue variable in the array data?
A)There is nothing wrong.
B)There is a compile-time error.
C)There is a bounds error.
D)There is a logic error.

A)There is nothing wrong.
B)There is a compile-time error.
C)There is a bounds error.
D)There is a logic error.
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
30
What is the output of the following code snippet?
A)86 2 24 4
B)86 24 3 4
C)1 86 24 4
D)1 2 24 86

A)86 2 24 4
B)86 24 3 4
C)1 86 24 4
D)1 2 24 86
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
31
Suppose you wish to write a method that returns the sum of the elements in partially filled array.Which is the best choice for a method header?
A)public int sum(int[] values)
B)public int sum()
C)public int sum(int[] values, int currSize)
D)public int sum(int[] values, int size, int currSize)
A)public int sum(int[] values)
B)public int sum()
C)public int sum(int[] values, int currSize)
D)public int sum(int[] values, int size, int currSize)
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
32
It may be necessary to "grow" an array when reading inputs because
A)the number of inputs may not be known in advance.
B)arrays in Java must be resized after every 100 elements.
C)arrays are based on powers of two.
D)the only alternative is a bounds exception.
A)the number of inputs may not be known in advance.
B)arrays in Java must be resized after every 100 elements.
C)arrays are based on powers of two.
D)the only alternative is a bounds exception.
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
33
Which code snippet calculates the sum of all the even elements in an array values?
A)
B)
C)
D)
A)

B)

C)

D)

Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
34
Select the statement that reveals the logic error in the following method.
A)double m = minimum(new double[] { 1.2, -3.5, 6.6, 2.4 });
B)double m = minimum(new double[] { 1.2, 23.5, 16.6, -23.4 });
C)double m = minimum(new double[] { -10.2, 3.5, 62.6, 21.4 });
D)double m = minimum(new double[] { 12.2, 31.5, 6.6, 2.4 });
![<strong>Select the statement that reveals the logic error in the following method. </strong> A)double m = minimum(new double[] { 1.2, -3.5, 6.6, 2.4 }); B)double m = minimum(new double[] { 1.2, 23.5, 16.6, -23.4 }); C)double m = minimum(new double[] { -10.2, 3.5, 62.6, 21.4 }); D)double m = minimum(new double[] { 12.2, 31.5, 6.6, 2.4 });](https://d2lvgg3v3hfg70.cloudfront.net/TB7392/11eb9782_fd7d_9375_b9fe_dd06874c01cd_TB7392_00.jpg)
A)double m = minimum(new double[] { 1.2, -3.5, 6.6, 2.4 });
B)double m = minimum(new double[] { 1.2, 23.5, 16.6, -23.4 });
C)double m = minimum(new double[] { -10.2, 3.5, 62.6, 21.4 });
D)double m = minimum(new double[] { 12.2, 31.5, 6.6, 2.4 });
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
35
When the order of the elements is unimportant, what is the most efficient way to remove an element from an array?
A)Delete the element and move each element after that one to a lower index.
B)Replace the element to be deleted with the last element in the array.
C)Replace the element to be deleted with the first element in the array.
D)Replace the element with the next element.
A)Delete the element and move each element after that one to a lower index.
B)Replace the element to be deleted with the last element in the array.
C)Replace the element to be deleted with the first element in the array.
D)Replace the element with the next element.
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
36
Consider the following code snippet:
In Java 6 and later, which statement copies the data array to the data2 array?
A)data2 = Arrays.copyOf(data, data2.length);
B)data2 = Arrays.copyOf(data, data.length);
C)data2 = Arrays.copyOf(data, data.size());
D)data2 = Arrays.copyOf(data);

A)data2 = Arrays.copyOf(data, data2.length);
B)data2 = Arrays.copyOf(data, data.length);
C)data2 = Arrays.copyOf(data, data.size());
D)data2 = Arrays.copyOf(data);
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
37
Assume the array of integers values has been created.Which condition must be used in the indicated area so the loop below will assign max the largest value in values?
A)current > max
B)max > current
C)max > values[current]
D)values[current] > max
![<strong>Assume the array of integers values has been created.Which condition must be used in the indicated area so the loop below will assign max the largest value in values? </strong> A)current > max B)max > current C)max > values[current] D)values[current] > max](https://d2lvgg3v3hfg70.cloudfront.net/TB7392/11eb9782_fd7c_0cce_b9fe_47ee2110e718_TB7392_00.jpg)
A)current > max
B)max > current
C)max > values[current]
D)values[current] > max
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
38
Assume the array of integers values has been created and process is a method that has a single integer parameter.Which of the following is equivalent to the loop below?
A)
B)
C)
D)

A)

B)

C)

D)

Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
39
Assume the variable numbers has been declared to be an array that has at least one element.Which is the following represents the last element in numbers?
A)numbers[numbers.length]
B)numbers.length
C)numbers[-1]
D)numbers[numbers.length - 1]
A)numbers[numbers.length]
B)numbers.length
C)numbers[-1]
D)numbers[numbers.length - 1]
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
40
Consider the following code snippet.Which statement should be used to fill in the empty line so that the output will be [32, 54, 67.5, 29, 35]?
A)String str = Arrays.format(data);
B)String str = data.toString();
C)String str = Arrays.toString(data);
D)String str = str + ", " + data[i];
![<strong>Consider the following code snippet.Which statement should be used to fill in the empty line so that the output will be [32, 54, 67.5, 29, 35]? </strong> A)String str = Arrays.format(data); B)String str = data.toString(); C)String str = Arrays.toString(data); D)String str = str + , + data[i];](https://d2lvgg3v3hfg70.cloudfront.net/TB7392/11eb9782_fd7d_6c64_b9fe_f1c286f94218_TB7392_00.jpg)
A)String str = Arrays.format(data);
B)String str = data.toString();
C)String str = Arrays.toString(data);
D)String str = str + ", " + data[i];
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
41
Assume the method doSomething has been defined as follows:
What does the method do?
A)It copies the integer array values to a new array.
B)It swaps the integer values stored in positions p1 and p2 of the array values.
C)It moves each element of the array values to a higher index position.
D)It inserts a new value into the array values.

A)It copies the integer array values to a new array.
B)It swaps the integer values stored in positions p1 and p2 of the array values.
C)It moves each element of the array values to a higher index position.
D)It inserts a new value into the array values.
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
42
Consider the code snippet below:
When the loop finishes what does the value of the boolean variable found indicate?
A)the size of the array values
B)whether or not the value 42 was found in the array
C)whether or not the value 0 was found in the array
D)the position where the value 42 is located in the array

A)the size of the array values
B)whether or not the value 42 was found in the array
C)whether or not the value 0 was found in the array
D)the position where the value 42 is located in the array
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
43
Suppose you wish to process an array of values and eliminate any potential duplicate values stored in the array.Which array algorithms might be adapted for this?
A)find the minimum
B)remove an element
C)add an element
D)calculate the sum of the elements
A)find the minimum
B)remove an element
C)add an element
D)calculate the sum of the elements
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
44
The method findLargest should return the largest of any number of double values.For example, the call findLargest (3.4, -2.6, 2.9) should return 3.4 and the call findLargest (9.2, 17.6, 3.4, -2.6, 2.9) should return 17.6.Partial code to do this is given below:
What code will complete this method?
A)
B)
C)
D)

What code will complete this method?
A)

B)

C)

D)

Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
45
Assume the method createSomething has been defined as follows:
A)[3, 4, 5, 6]
B)[4, 4, 4]
C)[3, 3, 3, 3]
D)[4, 5, 6]
![<strong>Assume the method createSomething has been defined as follows: </strong> A)[3, 4, 5, 6] B)[4, 4, 4] C)[3, 3, 3, 3] D)[4, 5, 6]](https://d2lvgg3v3hfg70.cloudfront.net/TB7392/11eb9782_fd7e_cbfd_b9fe_3fbdf25e0df0_TB7392_00.jpg)
A)[3, 4, 5, 6]
B)[4, 4, 4]
C)[3, 3, 3, 3]
D)[4, 5, 6]
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
46
What will be printed by the statements below?
A)0
B)1
C)2
D)3

A)0
B)1
C)2
D)3
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
47
What will be printed by the statements below?
A)7 5 6 4
B)7 6 5 4
C)7 5 6 7
D)4 5 6 4

A)7 5 6 4
B)7 6 5 4
C)7 5 6 7
D)4 5 6 4
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
48
The integer array numbers will be filled with values from the Scanner object in.If there are more input values than there are spaces in the array, only enough values to fill the array should be read.The integer variable currentSize should be set to the number of values read.Partial code to do this is given below:
What condition will complete this code?
A)currentSize < numbers.length && in.hasNextInt()
B)currentSize < numbers.length || in.hasNextInt()
C)currentSize <= numbers.length && in.hasNextInt()
D)currentSize <= numbers.length || in.hasNextInt()

A)currentSize < numbers.length && in.hasNextInt()
B)currentSize < numbers.length || in.hasNextInt()
C)currentSize <= numbers.length && in.hasNextInt()
D)currentSize <= numbers.length || in.hasNextInt()
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
49
Which statements about array algorithms are true?
I.The array algorithms are building blocks for many programs that process arrays.
II.Java contains ready-made array algorithms for every problem situation.
III.It is inefficient to make multiple passes through an array if you can do everything in one pass.
A)I, II only
B)I, III only
C)II, III only
D)I, II, III
I.The array algorithms are building blocks for many programs that process arrays.
II.Java contains ready-made array algorithms for every problem situation.
III.It is inefficient to make multiple passes through an array if you can do everything in one pass.
A)I, II only
B)I, III only
C)II, III only
D)I, II, III
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
50
Which code snippet finds the largest value in an array that is only partially full?
A)
B)
C)
D)
A)

B)

C)

D)

Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
51
Suppose you wish to use an array to solve a new problem.What is the first step to take in finding a solution?
A)structure a program using methods
B)adapt a built-in array algorithm
C)decompose the problem into steps
D)assemble a test program and run it
A)structure a program using methods
B)adapt a built-in array algorithm
C)decompose the problem into steps
D)assemble a test program and run it
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
52
The code snippet below is intended to perform a linear search on the array values to find the location of the value 42.What is the error in the code snippet?
A)The boolean variable found should be initialized to false.
B)The condition in the while loop should be (pos <= values.length && !found).
C)The variable pos should be initialized to 1.
D)The condition in the if statement should be (values[pos] <= searchedValue).
![<strong>The code snippet below is intended to perform a linear search on the array values to find the location of the value 42.What is the error in the code snippet? </strong> A)The boolean variable found should be initialized to false. B)The condition in the while loop should be (pos <= values.length && !found). C)The variable pos should be initialized to 1. D)The condition in the if statement should be (values[pos] <= searchedValue).](https://d2lvgg3v3hfg70.cloudfront.net/TB7392/11eb9782_fd80_0485_b9fe_510a5549fb47_TB7392_00.jpg)
A)The boolean variable found should be initialized to false.
B)The condition in the while loop should be (pos <= values.length && !found).
C)The variable pos should be initialized to 1.
D)The condition in the if statement should be (values[pos] <= searchedValue).
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
53
This code snippet is an implementation of what algorithm?
A)removing an array element
B)finding the maximum value in an array
C)calculating the mean of values in an array
D)sequential search

A)removing an array element
B)finding the maximum value in an array
C)calculating the mean of values in an array
D)sequential search
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
54
What will be printed by the statements below?
A)4 9 11 13
B)4 9 15 22
C)9 11 13 7
D)4 5 6 7

A)4 9 11 13
B)4 9 15 22
C)9 11 13 7
D)4 5 6 7
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
55
Assume the method doSomething has been defined as follows:
What does the method do?
A)It copies the integer array values to a new array.
B)It copies all but the first element in the integer array values to a new array.
C)It moves each element of the array values to a lower index position and overwrites the first element.
D)It overwrites all the values stored in the integer array values with the value stored in position 0.

A)It copies the integer array values to a new array.
B)It copies all but the first element in the integer array values to a new array.
C)It moves each element of the array values to a lower index position and overwrites the first element.
D)It overwrites all the values stored in the integer array values with the value stored in position 0.
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
56
Consider using a deck of cards as a way to visualize a shuffle algorithm.When two cards shuffle their position, what has to happen to the size of the array holding them?
A)It increases by one.
B)It decreases by one.
C)It stays the same.
D)It increases by two.
A)It increases by one.
B)It decreases by one.
C)It stays the same.
D)It increases by two.
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
57
Assume the method doSomething has been defined as follows:
What is printed by the statements below?
int [] nums = {3, 18, 29, -2} ;
System.out.print(Arrays.toString(doSomething(nums)));
A)[4, 19, 30, -1]
B)[21, 47, 27]
C)[21, 50, 48]
D)[3, 21, 47, 27]
![<strong>Assume the method doSomething has been defined as follows: What is printed by the statements below? int [] nums = {3, 18, 29, -2} ; System.out.print(Arrays.toString(doSomething(nums))); </strong> A)[4, 19, 30, -1] B)[21, 47, 27] C)[21, 50, 48] D)[3, 21, 47, 27]](https://d2lvgg3v3hfg70.cloudfront.net/TB7392/11eb9782_fd7e_f30e_b9fe_e96ad4c6d67f_TB7392_00.jpg)
int [] nums = {3, 18, 29, -2} ;
System.out.print(Arrays.toString(doSomething(nums)));
A)[4, 19, 30, -1]
B)[21, 47, 27]
C)[21, 50, 48]
D)[3, 21, 47, 27]
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
58
Assume the method doSomething has been defined as follows:
What does the method do?
A)It copies the integer array values to a new array.
B)It swaps the integer values stored in positions p1 and p2 of the array values.
C)It moves each element of the array values to a higher index position.
D)It overwrites the value stored in the integer array values at position p1 with the value stored in position p2.

A)It copies the integer array values to a new array.
B)It swaps the integer values stored in positions p1 and p2 of the array values.
C)It moves each element of the array values to a higher index position.
D)It overwrites the value stored in the integer array values at position p1 with the value stored in position p2.
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
59
The binary search is more efficient than the linear search, providing
A)the size of the array is a power of two.
B)the elements of the array are ordered.
C)the elements of the array are unordered.
D)the element being searched for is actually in the array.
A)the size of the array is a power of two.
B)the elements of the array are ordered.
C)the elements of the array are unordered.
D)the element being searched for is actually in the array.
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
60
Assume the method doSomething has been defined as follows:
What does the method do?
A)It copies the integer array values to a new array.
B)It swaps the integer values stored in positions i and i - 1 of the array values.
C)It moves each element of the array values to a lower index position and overwrites the first element.
D)It overwrites all the values stored in the integer array values with the value stored in position 0.

A)It copies the integer array values to a new array.
B)It swaps the integer values stored in positions i and i - 1 of the array values.
C)It moves each element of the array values to a lower index position and overwrites the first element.
D)It overwrites all the values stored in the integer array values with the value stored in position 0.
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
61
Consider the following code snippet:
What is the output of the given code snippet on execution?
A)5
B)7
C)9
D)10

A)5
B)7
C)9
D)10
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
62
Consider the following 2-dimensional array.Which expression gives the number of elements in the third row?
A)counts[2].size()
B)counts.length[2]
C)counts.length
D)counts[2].length
![<strong>Consider the following 2-dimensional array.Which expression gives the number of elements in the third row? </strong> A)counts[2].size() B)counts.length[2] C)counts.length D)counts[2].length](https://d2lvgg3v3hfg70.cloudfront.net/TB7392/11eb9782_fd81_641c_b9fe_f7ef147c9ff1_TB7392_00.jpg)
A)counts[2].size()
B)counts.length[2]
C)counts.length
D)counts[2].length
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
63
Why is the use of physical objects helpful in algorithm design?
A)It simulates the way the computer actually implements the algorithm.
B)It is more abstract than using a pencil and paper.
C)Because the constraints on physical things are the same as the constraints on bits and bytes.
D)Many people feel it is less intimidating than drawing diagrams.
A)It simulates the way the computer actually implements the algorithm.
B)It is more abstract than using a pencil and paper.
C)Because the constraints on physical things are the same as the constraints on bits and bytes.
D)Many people feel it is less intimidating than drawing diagrams.
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
64
What is the output of the following code?
A)2
B)3
C)4
D)5

A)2
B)3
C)4
D)5
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
65
Which one of the following is the correct definition for initializing data in a two-dimensional array with three rows and two columns?
A)
B)
C)
D)
A)

B)

C)

D)

Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
66
Which one of the following statements is the correct declaration for a two-dimensional array of 20 rows and 2 columns of type int?
A)int[][] num = new int[20][2];
B)int[][] num = new int[2][20];
C)int[][] num = new int[20,2];
D)int[][] num = new int[2,20];
A)int[][] num = new int[20][2];
B)int[][] num = new int[2][20];
C)int[][] num = new int[20,2];
D)int[][] num = new int[2,20];
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
67
Assume the following variable has been declared and given a value as shown:
Which is the value of data.length?
A)4
B)3
C)12
D)6

A)4
B)3
C)12
D)6
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
68
Consider the following code snippet:
What is the output of the given code snippet on execution?
A)5
B)6
C)7
D)9

A)5
B)6
C)7
D)9
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
69
Consider the telephone book as a physical object that can help understand algorithms.What kind of algorithm might be visualized using it?
A)sorting
B)searching
C)finding the maximum
D)Monte Carlo methods
A)sorting
B)searching
C)finding the maximum
D)Monte Carlo methods
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
70
Consider the following code snippet:
int val = arr[0][2];
Which value of arr is stored in the val variable?
A)the value in the first row and the second column
B)the value in the first row and the first column
C)the value in the first row and the third column
D)the value in the third row and the second column
int val = arr[0][2];
Which value of arr is stored in the val variable?
A)the value in the first row and the second column
B)the value in the first row and the first column
C)the value in the first row and the third column
D)the value in the third row and the second column
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
71
Assume the following variable has been declared and given a value as shown:
Which is the value of data[1][2]?
A)0
B)17
C)15
D)2
![<strong>Assume the following variable has been declared and given a value as shown: Which is the value of data[1][2]? </strong> A)0 B)17 C)15 D)2](https://d2lvgg3v3hfg70.cloudfront.net/TB7392/11eb9782_fd82_0061_b9fe_af3011238fd9_TB7392_00.jpg)
A)0
B)17
C)15
D)2
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
72
Which statement(s) about the size of a Java array, array list, and string are true?
I.The syntax for determining the size of an array, an array list, and a string in Java is consistent among the three.
II.The string uses s.size(), while the array list uses a.length().
III.The array uses a.length, which is not a method call.
A)I only
B)II only
C)III only
D)II, III only
I.The syntax for determining the size of an array, an array list, and a string in Java is consistent among the three.
II.The string uses s.size(), while the array list uses a.length().
III.The array uses a.length, which is not a method call.
A)I only
B)II only
C)III only
D)II, III only
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
73
Which one of the following statements is correct for displaying the value in the second row and the third column of a two-dimensional, size 3 by 4 array?
A)System.out.println(arr[1][2]);
B)System.out.println(arr[2][3]);
C)System.out.println(arr[2][1]);
D)System.out.println(arr[3][2]);
A)System.out.println(arr[1][2]);
B)System.out.println(arr[2][3]);
C)System.out.println(arr[2][1]);
D)System.out.println(arr[3][2]);
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
74
How many elements can be stored in an array of dimension 2 by 3?
A)2
B)3
C)5
D)6
A)2
B)3
C)5
D)6
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
75
If a programmer confuses the method required for checking the length of a string and uses size() instead of length(), what will happen?
A)The program will crash.
B)The program will not compile.
C)The program will run but will produce an uncertain result.
D)The compiler will automatically correct the error.
A)The program will crash.
B)The program will not compile.
C)The program will run but will produce an uncertain result.
D)The compiler will automatically correct the error.
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
76
Consider the following code snippet:
What is the value of numarray[1][2] after the code snippet is executed?
A)2
B)5
C)3
D)4
![<strong>Consider the following code snippet: What is the value of numarray[1][2] after the code snippet is executed? </strong> A)2 B)5 C)3 D)4](https://d2lvgg3v3hfg70.cloudfront.net/TB7392/11eb9782_fd80_a0c7_b9fe_9fffb615c924_TB7392_00.jpg)
A)2
B)5
C)3
D)4
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
77
Assume the following variable has been declared and given a value as shown:
Which is the value of data[0].length?
A)21
B)12
C)4
D)3
![<strong>Assume the following variable has been declared and given a value as shown: Which is the value of data[0].length? </strong> A)21 B)12 C)4 D)3](https://d2lvgg3v3hfg70.cloudfront.net/TB7392/11eb9782_fd81_d950_b9fe_5fe3c9ba7214_TB7392_00.jpg)
A)21
B)12
C)4
D)3
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
78
Which one of the following is a valid signature of a method with an integer two-dimensional array parameter of size 10 x 10?
A)public void func(int[][] arr)
B)public void func(int[10][] arr)
C)public void func(int[][10] arr)
D)public void func(int[10][10] arr)
A)public void func(int[][] arr)
B)public void func(int[10][] arr)
C)public void func(int[][10] arr)
D)public void func(int[10][10] arr)
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
79
Consider the following code snippet:
Identify the appropriate statement to display the value 24 from the given array?
A)System.out.println(arr[1][2]);
B)System.out.println(arr[2][2]);
C)System.out.println(arr[1][1]);
D)System.out.println(arr[2][1]);
![<strong>Consider the following code snippet: Identify the appropriate statement to display the value 24 from the given array? </strong> A)System.out.println(arr[1][2]); B)System.out.println(arr[2][2]); C)System.out.println(arr[1][1]); D)System.out.println(arr[2][1]);](https://d2lvgg3v3hfg70.cloudfront.net/TB7392/11eb9782_fd81_15fa_b9fe_378455ad1e69_TB7392_00.jpg)
A)System.out.println(arr[1][2]);
B)System.out.println(arr[2][2]);
C)System.out.println(arr[1][1]);
D)System.out.println(arr[2][1]);
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck
80
Consider the following code snippet:
What is the output of the given code snippet?
A)00
B)31
C)30
D)03

A)00
B)31
C)30
D)03
Unlock Deck
Unlock for access to all 117 flashcards in this deck.
Unlock Deck
k this deck