AP计算机教程7-8:中等多选题
0:00
What is printed as a result of executing the following code segment?
List<Integer> list1 = new ArrayList<Integer>(); list1.add(new Integer(1)); list1.add(new Integer(2)); list1.add(new Integer(3)); list1.set(2, new Integer(4)); list1.add(2, new Integer(5)); list1.add(new Integer(6)); System.out.println(list1);
Given the following code and assume that nums
initially contains [0, 0, 4, 2, 5, 0, 3]
, what will nums
contain as a result of executing numQuest
?
private List<Integer> nums; // precondition: nums.size() > 0; // nums contains Integer objects public void numQuest() { int k = 0; Integer zero = new Integer(0); while (k < nums.size()) { if (nums.get(k).equals(zero)) nums.remove(k); else k++; } }
0
。Which of the following best describes the behavior of process1
and process2
(shown below)?
public static List<Integer> process1(int n) { List<Integer> someList = new ArrayList<Integer>(); for (int k = 0; k < n; k++) someList.add(k); return someList; } public static List<Integer> process2(int n) { List<Integer> someList = new ArrayList<Integer>(); for (int k = 0; k < n; k++) someList.add(k, k); return someList; }
process2
实际上也一直是在列表尾部插入元素,和process1
没有区别。What is printed as a result of executing the following code segment?
List<Integer> aList = new ArrayList<Integer>(); aList.add(new Integer(1)); aList.add(new Integer(2)); aList.add(1, new Integer(5)); aList.set(1, new Integer(4)); aList.add(new Integer(6)); aList.add(new Integer(3)); System.out.println(aList);
What is printed as a result of executing the following code segment?
List<Integer> aList = new ArrayList<Integer>(); aList.add(new Integer(1)); aList.add(new Integer(2)); aList.remove(1); aList.add(1, new Integer(3)); aList.set(1, new Integer(4)); aList.add(new Integer(5)); System.out.println(list);
What is printed as a result of executing the following code segment?
List<String> list1 = new ArrayList<String>(); list1.add("a"); list1.add("b"); list1.add(0, "c"); list1.add(1, "d"); list1.set(2, "e"); list1.add("f"); System.out.println(list1);
e
把a
给替换了。Given the list nums = [4, 2, 3, 4, 5]
what is the result after executing nums.remove(4)
?
4
对应的是最后的元素5
。What is printed as a result of executing the following code segment?
List<String> list1 = new ArrayList<String>(); list1.add("a"); list1.add("b"); list1.add(0,"c"); list1.set(1, "d"); list1.set(0, "e"); list1.add("b"); System.out.println(list1);
Assume that numList
has been initialized with the following Integer objects: [0, 1, 2, 3, 4]
. What is the value of numList
after mystery(5)
executes?
private List<Integer> numList; public void mystery(int n) { for (int i = 0; i < n; i++) { Integer obj = numList.remove(0); numList.add(obj); } }
Assume that numList
has been initialized with the following Integer objects: [5, 7, 8, 12]
. Which of the following shows the values in numList
after a call to mystery(11)
?
private List<Integer> numList; public void mystery(int value) { int i = 0; while (i < numList.size() && numList.get(i) < value) { i++; } numList.add(i, value); }
i = 3
时循环结束。
0 条评论