In: Computer Science
QUESTION 5
What is printed?
int[] aArray = {1, 2, 3, 4};
int[] bArray = {5, 6, 7, 8}; bArray = aArray;
System.out.print(bArray[2]);
1 points
QUESTION 6
What is printed?
public static void main(String[] args)
{ int[] aArray = { 1, 2, 3, 4 }; System.out.print(aArray[2]);
int i = aMeth(aArray);
System.out.print(i + "" + aArray[2]);
}
public static int aMeth(int[] iArray)
{ for (int i = 0; i < iArray.length; i++)
{ iArray[i]++;
} int[] bArray = { 5, 6, 7, 8 };
iArray = bArray;
return iArray[2]; }
1 points
QUESTION 7
Assuming that array myList is properly declared and initialized with values, what best describes the following code snippet?
double max = myList[0];
for (int i = 1; i < myList.length; i++) {
if (myList[i] > max) max = myList[i];
}
sets max to the largest index in the array |
||
sets max to the index of the largest value in the array |
||
sets max to the largest positive value in the array |
||
sets max to the largest value in the array |
1 points
QUESTION 8
Given the following two arrays, which of the following will copy the values from sourceArray into targetArray?
int[] sourceArray = {2, 3, 1, 5, 10};
int[] targetArray = new int[sourceArray.length];
sourceArray = targetArray; |
||
targetArray = sourceArray; |
||
targetArray[] = sourceArray[]; |
||
sourceArray.copyInto(targetArray, 0, sourceArray.length);; |
||
None of the above |
QUESTION 1
An array is an object
True
False
1 points
QUESTION 2
To add a new element on to the end of an array myArray,
assign a new value to element myArray[myArray.length] |
||
use the myArray.add method |
||
use the myArray.resize method followed by the myArray.add |
||
new elements can't be added on to the end of an array |
1 points
QUESTION 3
Assume myArray is a valid and instantiated array of int values. Also assume the user is asked for an int value arIndx, and enters -1.
myArray[arIndx] = 3;
will
set the [-1] element of myArray to 3, even though this memory isn't in myArray's memory |
||
cause a compiler error |
||
cause a runtime exception |
||
renumber myArray's elements to be from -1 to myArray.length-2 |
1 points
QUESTION 4
Note: Multiple Answer
Which of the following will add 1 to each element of an appropriately declared, created and initialized int[] iVals?
int i = iVals.length - 1; while (i >= 0) { iVals[i]++; i--; } |
||
for (int i: iVals) { i = i + 1; } |
||
for (int i: iVals) { iVals[i]++; } |
||
for (int i = 0; i < iVals.length; i++) { iVals[i] += 1 |
QUESTION 9
In order to perform a binary search on an array, which of the following must be true (select all that apply)?
The array must be ordered |
||
The array must contain integers |
||
The array must have an even number of elements |
||
The array must have an odd number of elements |
1 points
QUESTION 10
Command line arguments are made available to main() via an array of _______.
1 points
QUESTION 11
The first action performed in a binary search is
Determine the largest value in the array |
||
Determine the smallest value in the array |
||
Determine the mid-point of the array |
||
Determine if the array is sorted |
1 points
QUESTION 12
If an array contains unordered values, searching for a particular value
is accomplished with a linear search |
||
is accomplished with the bipolar search |
||
can't be done in Java |
||
requires multiple parallel processing threads |
1 points
QUESTION 13
What best describes the processing of the following method?
public static int[] mystery(int[] list) {
int[] result = new int[list.length];
for (int i = 0, j = result.length - 1;
i < list.length; i++, j--) {
result[j] = list[i];
}
return result;
}
Returns an array with the values from list sorted in ascending order |
||
Returns an array with the values from list sorted in descending order |
||
Returns an array with the values from list decremented by 1 |
||
Returns an array with the values from list reversed |
1 points
QUESTION 14
The first action performed in Selection Sort is
convert all values to integers |
||
find the largest value in the array |
||
locate the midpoint of the array |
||
find the smallest value in the array |
1 points
QUESTION 15
When Selection Sort is run against an array the end result is
the values in the array are reordered smallest to largest |
||
the array is unchanged because the sorted values are placed in a different array |
||
none of the other answers are correct |
||
the values in the array are reordered largest to smallest |
1. Answer: True, they are object that can be dynamically created and assigned variable values
2. Answer: new elements can't be added on to the end of an array, as the size of the array is fixed. We can make arrays dynamic using arraylist
3. Answer: cause a runtime exception as ArrayIndexOutOfBoundException
4. Answer: a and d
int i = iVals.length - 1;
while (i >= 0)
{
iVals[i]++; i--;
}
And
for (int i = 0; i < iVals.length; i++)
{
iVals[i] += 1
}
5 Answer: 3, as the value of first array is assigned to second array
6. Answer: 3, 7 and 4 are the values obtained as output
7. Answer: Sets max to the largest value in the array
8. Answer: targetArray = sourceArray;
9. Answer: to perform binary search The array must be ordered and The array must contains integers
10.Answer: Array of strings represented mostly as args
11.Answer: Determine the mid-point of the array
12. Answer: is accomplished with a linear search
13. Answer: Returns an array with the values from list sorted in descending order
14 Answer: find the smallest value in the array
15. Answer: the values in the array are reordered smallest to largest