id:

TEST3

Reference classes here
 MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

 MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Which of the following is a legal way to declare and instantiate an array of 10 Strings? 1) a b c d e
 A)  String[ ] s = new String[10]; B)  String s = new String[10]; C)  String[ ] s = new String; D)  String[10] s = new String; E)  String s = new String(10);

 2) What does the following code do? Assume list is an array of int values, temp is some previously initialized int value, and c is an int initialized to 0. for(j=0;j
 A)  It counts the number of elements in list that are less than temp B)  It sorts the values in list to be in ascending order C)  It finds the smallest value and stores it in temp D)  It counts the number of elements equal to the smallest value in list E)  It finds the largest value and stores it in temp

 An int array stores the following values. Use the array to answer the question(s) below. 3) Which of the following lists of numbers would accurately show the array after the first pass through the Selection Sort algorithm? 3) a b c d e
 A)  2, 4, 12, 9, 6, 8, 18 B)  2, 4, 6, 8, 9, 12, 18 C)  2, 4, 9, 12, 6, 8, 18 D)  4, 9, 12, 2, 6, 8, 18 E)  9, 4, 12, 2, 6, 8, 18

 For the question(s) below, assume an int array, candy, stores the number of candy bars sold by a group of children where candy[j] is the number of candy bars sold by child j. Assume there are 12 children in all. 4) Which of the following code could be used to compute the total number of bars sold by the children? 4) a b c d e
 A)  for(int j=0; j<12; j++) sum+= candy[j]; B)  for(int j=0; j<12; j++) candy[j] = sum; C)  for(int j=0; j<12; j++) sum = candy[j]; D)  for(int j=0; j<12; j++) sum += [j]; E)  for(int j=0; j<12; j++) [j] += sum;

 5) What does the following method do? public int question15( ) { int value1 = 0;int value2 = 0; for(int j=0; j<12; j++) if(candy[j] > value1) { value1 = candy[j]; value2 = j; } return value2; } 5) a b c d e
 A)  It returns the total number of candy bars sold B)  It returns the index of the child who sold the most candy bars C)  It returns the number of candy bars sold by the child who sold the most candy bars D)  It returns the total number of children who sold 0 candy bars E)  It returns the total number of children who sold more than 0 candy bars

 6) To declare a two-dimensional int array called threeD, which of the following would you use? 6) a b c d e
 A)  int[2] twoD; B)  int[ , ] twoD; C)  int [ [ ] ] twoD; D)  int[ ] twoD[2]; E)  int[ ][ ] twoD;

 7) Which of the following correctly declares an ArrayList of Car objects? 7) a b c d e
 A)  ArrayList cars = Car; B)  ArrayList Car[] cars; C)  ArrayList[Car] cars; D)  ArrayList cars; E)  ArrayList Car;

 8) Which of the following expressions gives the last element in the ArrayList alist? 8) a b c d e
 A)  alist.last() B)  alist.get(alist.size()-1) C)  alist.get(alist.size()) D)  alist.get(alist.last()) E)  alist.get(alist.length())

 9) To initialize a String array names to store the three Strings "Huey", "Duey" and "Louie", you would do 9) a b c d e
 A)  String names = {"Huey", "Duey", "Louie"}; B)  String[ ] names = {"Huey", "Duey", "Louie"}; C)  String[ ] names = new String{"Huey", "Duey", "Louie"}; D)  String names[3] = {"Huey", "Duey", "Louie"}; E)  String names; names[0] = "Huey"; names[1] = "Duey"; names[2] = "Louie";

 10) Which of the following statements loops through every element in the ArrayList alist? 10) a b c d e
 A)  for (alist : Object item) B)  for (item in alist) C)  for (Object alist : item) D)  for (Object item : alist) E)  for (Object item = null; item : alist)

 11) Which of the following statements adds item to the end of the ArrayList alist? 11) a b c d e
 A)  alist.add(item); B)  alist.set(alist.size()-1, item); C)  item.addtoEnd(alist); D)  alist[alist.size()-1] = item; E)  both A and B

 12) An ArrayList of Strings called names contains "John", "Jack", and "Adam". To change "John" to "Kevin" we would say: 12) a b c d e
 A)  names.set(1,"Kevin"); B)  names.set(0,"Kevin"); C)  names.get(0)="Kevin"; D)  names.get(1)="Kevin";

 13) Assume the above statement was executed correctly. The effect of the following code fragment would be:for (i=0; i
 A)  It would remove John B)  It would remove all names C)  It would remove Kevin D)  It would have no effect