- Which of the following are correct?
String[] list = {“red”, “yellow”, “green”};
String[] list = new String[]{“red”, “yellow”, “green”};
2. Analyze the following code:
int[] list = new int[5]; list = new int[6];
The code can compile and run fine. The second line assigns a new array to list.
3. The reverse method is defined in this section. What is list1 after executing the following statements?
int[] list1 = {1, 2, 3, 4, 5, 6}; int[] list2 = reverse(list1);
list1 is 1 2 3 4 5 6
4. Analyze the following code:
public class Test {
public static void main(String[] args) {
boolean[][] x = new boolean[3][]; x[0] = new boolean[1];
x[1] = new boolean[2]; x[2] = new boolean[3];
System.out.println(“x[2][2] is ” + x[2][2]);
}
}
The program runs and displays x[2][2] is false.
5. Consider the array declaration and instantiation: int[ ] arr = new int[5]; Which of the following is true about arr?
It stores 5 elements with legal indices between 0 and 4
6.The following code accomplishes which of the tasks written below? Assume list is an int array that stores positive int values only.
int foo = 0;
for (int j =0 ; j < list.length; j++)
if (list[j] > foo) foo = list[j];
It stores the largest value in list (the maximum) in foo
7. The statement int[ ] list = {5, 10, 15, 20};
initializes list to have 4 int values
8. To initialize a String array names to store the three Strings “Huey”, “Duey” and “Louie”, you would do
String[ ] names = {“Huey”, “Duey”, “Louie”};
9. In a two-dimensional array, both dimensions must have the same number of elements, as in[10][10].
False
Other Links:
See other websites for quiz:
Check on QUIZLET