Assignment 7 Question
What would be the result of executing the following code? int[] x = {0, 1, 2, 3, 4, 5}; Select one: A. A compiler error will occur. B. An array of 6 values, ranging from 0 through 5 and referenced by the variable x will be created. C. The variable x will contain the values 0 through 5. D. An array of 6 values, all initialized to 0 and referenced by the variable x will be created.
An array of 6 values, ranging from 0 through 5 and referenced by the variable x will be created
Which of the following import statements is required in order to use the ArrayList class? Select one: A. import java.util.Tools; B. import java.util.API; C. import java.util.ArrayList; D. import java.util.Containers;
import java.util.ArrayList;
What does the following statement do? double[] array1 = new double[10]; Select one: A. It will allow valid subscripts in the range of 0 through 9. B. It declares array1 to be a reference to an array of double values. C. It creates an instance of an array of ten double values. D. It does all of these.
it does all of these
What will be the result after the following code is executed? final int ARRAY_SIZE = 5; float[] x= float[ARRAY_SIZE]; for (i=1; i<ARRAY_SIZE; i++){ x[i]=10.0; } Select one: A. A runtime error will occur. B. All the values in the array except the first will be set to 10.0. C. All the values in the array will be initialized to 10.0. D. The code contains a syntax error and will not compile.
The code contains a syntax error and will not compile.
What would be the result after the following code is executed? int[] number=(40,3,5,7,8,12,10); int value=number[0]; for (int i=1; I<numbers.length; i++) { if (numbers[i] < value) value = numbers[i]; } Select one: A. The value variable will contain the lowest value in the numbers array. B. The value variable will contain the average of all the values in the numbers array. C. The value variable will contain the sum of all the values in the numbers array. D. The value variable will contain the highest value in the numbers array.
The value variable will contain the lowest value in the numbers array.
An ArrayList object automatically expands in size to accommodate the items stored in it. Select one: True False
True
Objects in an array are accessed with subscripts, just like any other data type in an array. Select one: True False
True
The ________ method removes an item from an ArrayList at a specific index. Select one: A. remove B. clear C. deleteAt D. pop
remove
You can use the ________ method to replace an item at a specific location in an ArrayList. Select one: A. replace B. add C. set D. remove
set
Which method is used to determine the number of items stored in an ArrayList object? Select one: A. volume B. size C. items D. listLength
size
Which of the following methods returns a string representing all of the items stored in an ArrayList object? Select one: A. print B. show C. getList D. toString
toString
For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"}; Select one: A. a reference to the String object containing "ghi" B. "def" C. "ghi" D. a reference to the String object containing "def"
a reference to the String object containing "ghi"
Which of the following statements is(are) true about this code? final int ARRAY_SIZE = 10; long[] array1 = new long[ARRAY_SIZE]; Select one: A. It will allow valid subscripts in the range of 0 through 9. B. It creates an instance of an array of ten long values. C. It declares array1 to be a reference to an array of long values. D. All of these are true.
all of these are true
What would be the result after the following code is executed? int[] numbers = (50,10,15,20,25,100,30); int value = 0; for (int i=1; i<numbers.length; i++) value += numbers[i]; Select one: A. The value variable will contain the average of all the values in the numbers array. B. The value variable will contain the highest value in the numbers array. C. The value variable will contain the sum of all the values in the numbers array. D. The value variable will contain the lowest value in the numbers array.
The value variable will contain the sum of all the values in the numbers array.
Which of the following ArrayList class methods is used to insert an item at a specific location in an ArrayList? Select one: A. insert B. add C. set D. store
add
What does <String> specify in the following statement? ArrayList<String> nameList = new ArrayList<String>(); Select one: A. It specifies that the ArrayList will be converted to a String array. B. It specifies that everything stored in the ArrayList object will be converted to a String object. C. It specifies that only String objects may be stored in the ArrayList object. D. It specifies that String objects may not be stored in the ArrayList object.
It specifies that only String objects may be stored in the ArrayList object.